include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / staging / vt6655 / wmgr.c
blobab289c30edb4f085a0bdab2a9512c373dc300267
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
20 * File: wmgr.c
22 * Purpose: Handles the 802.11 management functions
24 * Author: Lyndon Chen
26 * Date: May 8, 2002
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
60 * Revision History:
64 #include "tmacro.h"
65 #include "desc.h"
66 #include "device.h"
67 #include "card.h"
68 #include "channel.h"
69 #include "80211hdr.h"
70 #include "80211mgr.h"
71 #include "wmgr.h"
72 #include "wcmd.h"
73 #include "mac.h"
74 #include "bssdb.h"
75 #include "power.h"
76 #include "datarate.h"
77 #include "baseband.h"
78 #include "rxtx.h"
79 #include "wpa.h"
80 #include "rf.h"
81 #include "iowpa.h"
83 #define PLICE_DEBUG
85 /*--------------------- Static Definitions -------------------------*/
89 /*--------------------- Static Classes ----------------------------*/
91 /*--------------------- Static Variables --------------------------*/
92 static int msglevel =MSG_LEVEL_INFO;
93 //static int msglevel =MSG_LEVEL_DEBUG;
95 /*--------------------- Static Functions --------------------------*/
96 //2008-8-4 <add> by chester
97 static bool ChannelExceedZoneType(
98 PSDevice pDevice,
99 unsigned char byCurrChannel
102 // Association/diassociation functions
103 static
104 PSTxMgmtPacket
105 s_MgrMakeAssocRequest(
106 PSDevice pDevice,
107 PSMgmtObject pMgmt,
108 unsigned char *pDAddr,
109 unsigned short wCurrCapInfo,
110 unsigned short wListenInterval,
111 PWLAN_IE_SSID pCurrSSID,
112 PWLAN_IE_SUPP_RATES pCurrRates,
113 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
116 static
117 void
118 s_vMgrRxAssocRequest(
119 PSDevice pDevice,
120 PSMgmtObject pMgmt,
121 PSRxMgmtPacket pRxPacket,
122 unsigned int uNodeIndex
125 static
126 PSTxMgmtPacket
127 s_MgrMakeReAssocRequest(
128 PSDevice pDevice,
129 PSMgmtObject pMgmt,
130 unsigned char *pDAddr,
131 unsigned short wCurrCapInfo,
132 unsigned short wListenInterval,
133 PWLAN_IE_SSID pCurrSSID,
134 PWLAN_IE_SUPP_RATES pCurrRates,
135 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
138 static
139 void
140 s_vMgrRxAssocResponse(
141 PSDevice pDevice,
142 PSMgmtObject pMgmt,
143 PSRxMgmtPacket pRxPacket,
144 bool bReAssocType
147 static
148 void
149 s_vMgrRxDisassociation(
150 PSDevice pDevice,
151 PSMgmtObject pMgmt,
152 PSRxMgmtPacket pRxPacket
155 // Authentication/deauthen functions
156 static
157 void
158 s_vMgrRxAuthenSequence_1(
159 PSDevice pDevice,
160 PSMgmtObject pMgmt,
161 PWLAN_FR_AUTHEN pFrame
164 static
165 void
166 s_vMgrRxAuthenSequence_2(
167 PSDevice pDevice,
168 PSMgmtObject pMgmt,
169 PWLAN_FR_AUTHEN pFrame
172 static
173 void
174 s_vMgrRxAuthenSequence_3(
175 PSDevice pDevice,
176 PSMgmtObject pMgmt,
177 PWLAN_FR_AUTHEN pFrame
180 static
181 void
182 s_vMgrRxAuthenSequence_4(
183 PSDevice pDevice,
184 PSMgmtObject pMgmt,
185 PWLAN_FR_AUTHEN pFrame
188 static
189 void
190 s_vMgrRxAuthentication(
191 PSDevice pDevice,
192 PSMgmtObject pMgmt,
193 PSRxMgmtPacket pRxPacket
196 static
197 void
198 s_vMgrRxDeauthentication(
199 PSDevice pDevice,
200 PSMgmtObject pMgmt,
201 PSRxMgmtPacket pRxPacket
204 // Scan functions
205 // probe request/response functions
206 static
207 void
208 s_vMgrRxProbeRequest(
209 PSDevice pDevice,
210 PSMgmtObject pMgmt,
211 PSRxMgmtPacket pRxPacket
214 static
215 void
216 s_vMgrRxProbeResponse(
217 PSDevice pDevice,
218 PSMgmtObject pMgmt,
219 PSRxMgmtPacket pRxPacket
222 // beacon functions
223 static
224 void
225 s_vMgrRxBeacon(
226 PSDevice pDevice,
227 PSMgmtObject pMgmt,
228 PSRxMgmtPacket pRxPacket,
229 bool bInScan
232 static
233 void
234 s_vMgrFormatTIM(
235 PSMgmtObject pMgmt,
236 PWLAN_IE_TIM pTIM
239 static
240 PSTxMgmtPacket
241 s_MgrMakeBeacon(
242 PSDevice pDevice,
243 PSMgmtObject pMgmt,
244 unsigned short wCurrCapInfo,
245 unsigned short wCurrBeaconPeriod,
246 unsigned int uCurrChannel,
247 unsigned short wCurrATIMWinodw,
248 PWLAN_IE_SSID pCurrSSID,
249 unsigned char *pCurrBSSID,
250 PWLAN_IE_SUPP_RATES pCurrSuppRates,
251 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
255 // Association response
256 static
257 PSTxMgmtPacket
258 s_MgrMakeAssocResponse(
259 PSDevice pDevice,
260 PSMgmtObject pMgmt,
261 unsigned short wCurrCapInfo,
262 unsigned short wAssocStatus,
263 unsigned short wAssocAID,
264 unsigned char *pDstAddr,
265 PWLAN_IE_SUPP_RATES pCurrSuppRates,
266 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
269 // ReAssociation response
270 static
271 PSTxMgmtPacket
272 s_MgrMakeReAssocResponse(
273 PSDevice pDevice,
274 PSMgmtObject pMgmt,
275 unsigned short wCurrCapInfo,
276 unsigned short wAssocStatus,
277 unsigned short wAssocAID,
278 unsigned char *pDstAddr,
279 PWLAN_IE_SUPP_RATES pCurrSuppRates,
280 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
283 // Probe response
284 static
285 PSTxMgmtPacket
286 s_MgrMakeProbeResponse(
287 PSDevice pDevice,
288 PSMgmtObject pMgmt,
289 unsigned short wCurrCapInfo,
290 unsigned short wCurrBeaconPeriod,
291 unsigned int uCurrChannel,
292 unsigned short wCurrATIMWinodw,
293 unsigned char *pDstAddr,
294 PWLAN_IE_SSID pCurrSSID,
295 unsigned char *pCurrBSSID,
296 PWLAN_IE_SUPP_RATES pCurrSuppRates,
297 PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
298 unsigned char byPHYType
301 // received status
302 static
303 void
304 s_vMgrLogStatus(
305 PSMgmtObject pMgmt,
306 unsigned short wStatus
310 static
311 void
312 s_vMgrSynchBSS (
313 PSDevice pDevice,
314 unsigned int uBSSMode,
315 PKnownBSS pCurr,
316 PCMD_STATUS pStatus
320 static bool
321 s_bCipherMatch (
322 PKnownBSS pBSSNode,
323 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
324 unsigned char *pbyCCSPK,
325 unsigned char *pbyCCSGK
328 static void Encyption_Rebuild(
329 PSDevice pDevice,
330 PKnownBSS pCurr
335 /*--------------------- Export Variables --------------------------*/
338 /*--------------------- Export Functions --------------------------*/
343 * Routine Description:
344 * Allocates and initializes the Management object.
346 * Return Value:
347 * Ndis_staus.
351 void
352 vMgrObjectInit(
353 void *hDeviceContext
356 PSDevice pDevice = (PSDevice)hDeviceContext;
357 PSMgmtObject pMgmt = pDevice->pMgmt;
358 int ii;
361 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
362 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
363 pMgmt->uCurrChannel = pDevice->uChannel;
364 for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
365 pMgmt->abyDesireBSSID[ii] = 0xFF;
367 pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
368 //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
369 pMgmt->byCSSPK = KEY_CTL_NONE;
370 pMgmt->byCSSGK = KEY_CTL_NONE;
371 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
372 BSSvClearBSSList((void *)pDevice, false);
374 return;
379 * Routine Description:
380 * Initializes timer object
382 * Return Value:
383 * Ndis_staus.
387 void
388 vMgrTimerInit(
389 void *hDeviceContext
392 PSDevice pDevice = (PSDevice)hDeviceContext;
393 PSMgmtObject pMgmt = pDevice->pMgmt;
396 init_timer(&pMgmt->sTimerSecondCallback);
397 pMgmt->sTimerSecondCallback.data = (unsigned long) pDevice;
398 pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
399 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
401 init_timer(&pDevice->sTimerCommand);
402 pDevice->sTimerCommand.data = (unsigned long) pDevice;
403 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
404 pDevice->sTimerCommand.expires = RUN_AT(HZ);
406 #ifdef TxInSleep
407 init_timer(&pDevice->sTimerTxData);
408 pDevice->sTimerTxData.data = (unsigned long) pDevice;
409 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
410 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
411 pDevice->fTxDataInSleep = false;
412 pDevice->IsTxDataTrigger = false;
413 pDevice->nTxDataTimeCout = 0;
414 #endif
416 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
417 pDevice->uCmdDequeueIdx = 0;
418 pDevice->uCmdEnqueueIdx = 0;
420 return;
427 * Routine Description:
428 * Reset the management object structure.
430 * Return Value:
431 * None.
435 void
436 vMgrObjectReset(
437 void *hDeviceContext
440 PSDevice pDevice = (PSDevice)hDeviceContext;
441 PSMgmtObject pMgmt = pDevice->pMgmt;
443 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
444 pMgmt->eCurrState = WMAC_STATE_IDLE;
445 pDevice->bEnablePSMode = false;
446 // TODO: timer
448 return;
454 * Routine Description:
455 * Start the station association procedure. Namely, send an
456 * association request frame to the AP.
458 * Return Value:
459 * None.
464 void
465 vMgrAssocBeginSta(
466 void *hDeviceContext,
467 PSMgmtObject pMgmt,
468 PCMD_STATUS pStatus
471 PSDevice pDevice = (PSDevice)hDeviceContext;
472 PSTxMgmtPacket pTxPacket;
475 pMgmt->wCurrCapInfo = 0;
476 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
477 if (pDevice->bEncryptionEnable) {
478 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
480 // always allow receive short preamble
481 //if (pDevice->byPreambleType == 1) {
482 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
484 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
485 if (pMgmt->wListenInterval == 0)
486 pMgmt->wListenInterval = 1; // at least one.
488 // ERP Phy (802.11g) should support short preamble.
489 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
490 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
491 if (CARDbIsShorSlotTime(pMgmt->pAdapter) == true) {
492 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
494 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
495 if (CARDbIsShortPreamble(pMgmt->pAdapter) == true) {
496 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
499 if (pMgmt->b11hEnable == true)
500 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
502 /* build an assocreq frame and send it */
503 pTxPacket = s_MgrMakeAssocRequest
505 pDevice,
506 pMgmt,
507 pMgmt->abyCurrBSSID,
508 pMgmt->wCurrCapInfo,
509 pMgmt->wListenInterval,
510 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
511 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
512 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
515 if (pTxPacket != NULL ){
516 /* send the frame */
517 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
518 if (*pStatus == CMD_STATUS_PENDING) {
519 pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
520 *pStatus = CMD_STATUS_SUCCESS;
523 else
524 *pStatus = CMD_STATUS_RESOURCES;
526 return ;
532 * Routine Description:
533 * Start the station re-association procedure.
535 * Return Value:
536 * None.
540 void
541 vMgrReAssocBeginSta(
542 void *hDeviceContext,
543 PSMgmtObject pMgmt,
544 PCMD_STATUS pStatus
547 PSDevice pDevice = (PSDevice)hDeviceContext;
548 PSTxMgmtPacket pTxPacket;
552 pMgmt->wCurrCapInfo = 0;
553 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
554 if (pDevice->bEncryptionEnable) {
555 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
558 //if (pDevice->byPreambleType == 1) {
559 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
561 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
563 if (pMgmt->wListenInterval == 0)
564 pMgmt->wListenInterval = 1; // at least one.
567 // ERP Phy (802.11g) should support short preamble.
568 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
569 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
570 if (CARDbIsShorSlotTime(pMgmt->pAdapter) == true) {
571 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
573 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
574 if (CARDbIsShortPreamble(pMgmt->pAdapter) == true) {
575 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
578 if (pMgmt->b11hEnable == true)
579 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
582 pTxPacket = s_MgrMakeReAssocRequest
584 pDevice,
585 pMgmt,
586 pMgmt->abyCurrBSSID,
587 pMgmt->wCurrCapInfo,
588 pMgmt->wListenInterval,
589 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
590 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
591 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
594 if (pTxPacket != NULL ){
595 /* send the frame */
596 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
597 if (*pStatus != CMD_STATUS_PENDING) {
598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
600 else {
601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
606 return ;
611 * Routine Description:
612 * Send an dis-association request frame to the AP.
614 * Return Value:
615 * None.
619 void
620 vMgrDisassocBeginSta(
621 void *hDeviceContext,
622 PSMgmtObject pMgmt,
623 unsigned char *abyDestAddress,
624 unsigned short wReason,
625 PCMD_STATUS pStatus
628 PSDevice pDevice = (PSDevice)hDeviceContext;
629 PSTxMgmtPacket pTxPacket = NULL;
630 WLAN_FR_DISASSOC sFrame;
632 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
633 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN);
634 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
636 // Setup the sFrame structure
637 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
638 sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
640 // format fixed field frame structure
641 vMgrEncodeDisassociation(&sFrame);
643 // Setup the header
644 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
646 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
647 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
650 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
651 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
652 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
654 // Set reason code
655 *(sFrame.pwReason) = cpu_to_le16(wReason);
656 pTxPacket->cbMPDULen = sFrame.len;
657 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
659 // send the frame
660 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
661 if (*pStatus == CMD_STATUS_PENDING) {
662 pMgmt->eCurrState = WMAC_STATE_IDLE;
663 *pStatus = CMD_STATUS_SUCCESS;
666 return;
673 * Routine Description:(AP function)
674 * Handle incoming station association request frames.
676 * Return Value:
677 * None.
681 static
682 void
683 s_vMgrRxAssocRequest(
684 PSDevice pDevice,
685 PSMgmtObject pMgmt,
686 PSRxMgmtPacket pRxPacket,
687 unsigned int uNodeIndex
690 WLAN_FR_ASSOCREQ sFrame;
691 CMD_STATUS Status;
692 PSTxMgmtPacket pTxPacket;
693 unsigned short wAssocStatus = 0;
694 unsigned short wAssocAID = 0;
695 unsigned int uRateLen = WLAN_RATES_MAXLEN;
696 unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
697 unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
700 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
701 return;
702 // node index not found
703 if (!uNodeIndex)
704 return;
706 //check if node is authenticated
707 //decode the frame
708 memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
709 memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
710 memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
711 sFrame.len = pRxPacket->cbMPDULen;
712 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
714 vMgrDecodeAssocRequest(&sFrame);
716 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
717 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
718 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
719 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
720 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
721 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
722 // Todo: check sta basic rate, if ap can't support, set status code
723 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
724 uRateLen = WLAN_RATES_MAXLEN_11B;
726 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
727 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
728 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
729 uRateLen);
730 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
731 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
732 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
733 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
734 uRateLen);
735 } else {
736 abyCurrExtSuppRates[1] = 0;
740 RATEvParseMaxRate((void *)pDevice,
741 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
742 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
743 false, // do not change our basic rate
744 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
745 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
746 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
747 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
748 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
751 // set max tx rate
752 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
753 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
754 #ifdef PLICE_DEBUG
755 printk("RxAssocRequest:wTxDataRate is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
756 #endif
757 // Todo: check sta preamble, if ap can't support, set status code
758 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
759 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
760 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
761 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
762 pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
763 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
764 wAssocAID = (unsigned short)uNodeIndex;
765 // check if ERP support
766 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
767 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
769 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
770 // B only STA join
771 pDevice->bProtectMode = true;
772 pDevice->bNonERPPresent = true;
774 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
775 pDevice->bBarkerPreambleMd = true;
778 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
779 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
780 sFrame.pHdr->sA3.abyAddr2[0],
781 sFrame.pHdr->sA3.abyAddr2[1],
782 sFrame.pHdr->sA3.abyAddr2[2],
783 sFrame.pHdr->sA3.abyAddr2[3],
784 sFrame.pHdr->sA3.abyAddr2[4],
785 sFrame.pHdr->sA3.abyAddr2[5]
787 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
788 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
789 }//else { TODO: received STA under state1 handle }
790 else {
791 return;
795 // assoc response reply..
796 pTxPacket = s_MgrMakeAssocResponse
798 pDevice,
799 pMgmt,
800 pMgmt->wCurrCapInfo,
801 wAssocStatus,
802 wAssocAID,
803 sFrame.pHdr->sA3.abyAddr2,
804 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
805 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
807 if (pTxPacket != NULL ){
809 if (pDevice->bEnableHostapd) {
810 return;
812 /* send the frame */
813 Status = csMgmt_xmit(pDevice, pTxPacket);
814 if (Status != CMD_STATUS_PENDING) {
815 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
817 else {
818 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
823 return;
829 * Description:(AP function)
830 * Handle incoming station re-association request frames.
832 * Parameters:
833 * In:
834 * pMgmt - Management Object structure
835 * pRxPacket - Received Packet
836 * Out:
837 * none
839 * Return Value: None.
843 static
844 void
845 s_vMgrRxReAssocRequest(
846 PSDevice pDevice,
847 PSMgmtObject pMgmt,
848 PSRxMgmtPacket pRxPacket,
849 unsigned int uNodeIndex
852 WLAN_FR_REASSOCREQ sFrame;
853 CMD_STATUS Status;
854 PSTxMgmtPacket pTxPacket;
855 unsigned short wAssocStatus = 0;
856 unsigned short wAssocAID = 0;
857 unsigned int uRateLen = WLAN_RATES_MAXLEN;
858 unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
859 unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
861 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
862 return;
863 // node index not found
864 if (!uNodeIndex)
865 return;
866 //check if node is authenticated
867 //decode the frame
868 memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
869 sFrame.len = pRxPacket->cbMPDULen;
870 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
871 vMgrDecodeReassocRequest(&sFrame);
873 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
874 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
875 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
876 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
877 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
878 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
879 // Todo: check sta basic rate, if ap can't support, set status code
881 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
882 uRateLen = WLAN_RATES_MAXLEN_11B;
885 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
886 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
887 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
888 uRateLen);
889 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
890 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
891 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
892 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
893 uRateLen);
894 } else {
895 abyCurrExtSuppRates[1] = 0;
899 RATEvParseMaxRate((void *)pDevice,
900 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
901 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
902 false, // do not change our basic rate
903 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
904 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
905 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
906 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
907 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
910 // set max tx rate
911 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
912 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
913 #ifdef PLICE_DEBUG
914 printk("RxReAssocRequest:TxDataRate is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
915 #endif
916 // Todo: check sta preamble, if ap can't support, set status code
917 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
918 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
919 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
920 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
921 pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
922 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
923 wAssocAID = (unsigned short)uNodeIndex;
925 // if suppurt ERP
926 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
927 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
929 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
930 // B only STA join
931 pDevice->bProtectMode = true;
932 pDevice->bNonERPPresent = true;
934 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
935 pDevice->bBarkerPreambleMd = true;
938 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
939 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
940 sFrame.pHdr->sA3.abyAddr2[0],
941 sFrame.pHdr->sA3.abyAddr2[1],
942 sFrame.pHdr->sA3.abyAddr2[2],
943 sFrame.pHdr->sA3.abyAddr2[3],
944 sFrame.pHdr->sA3.abyAddr2[4],
945 sFrame.pHdr->sA3.abyAddr2[5]
947 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
948 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
953 // assoc response reply..
954 pTxPacket = s_MgrMakeReAssocResponse
956 pDevice,
957 pMgmt,
958 pMgmt->wCurrCapInfo,
959 wAssocStatus,
960 wAssocAID,
961 sFrame.pHdr->sA3.abyAddr2,
962 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
963 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
966 if (pTxPacket != NULL ){
967 /* send the frame */
968 if (pDevice->bEnableHostapd) {
969 return;
971 Status = csMgmt_xmit(pDevice, pTxPacket);
972 if (Status != CMD_STATUS_PENDING) {
973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
975 else {
976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
979 return;
985 * Routine Description:
986 * Handle incoming association response frames.
988 * Return Value:
989 * None.
993 static
994 void
995 s_vMgrRxAssocResponse(
996 PSDevice pDevice,
997 PSMgmtObject pMgmt,
998 PSRxMgmtPacket pRxPacket,
999 bool bReAssocType
1002 WLAN_FR_ASSOCRESP sFrame;
1003 PWLAN_IE_SSID pItemSSID;
1004 unsigned char *pbyIEs;
1005 viawget_wpa_header *wpahdr;
1009 if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
1010 pMgmt->eCurrState == WMAC_STATE_ASSOC) {
1012 sFrame.len = pRxPacket->cbMPDULen;
1013 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1014 // decode the frame
1015 vMgrDecodeAssocResponse(&sFrame);
1016 if ((sFrame.pwCapInfo == 0) ||
1017 (sFrame.pwStatus == 0) ||
1018 (sFrame.pwAid == 0) ||
1019 (sFrame.pSuppRates == 0)){
1020 DBG_PORT80(0xCC);
1021 return;
1024 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
1025 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
1026 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
1027 pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
1029 pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
1030 pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1031 pbyIEs = pMgmt->sAssocInfo.abyIEs;
1032 pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1033 memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
1035 // save values and set current BSS state
1036 if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1037 // set AID
1038 pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
1039 if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
1041 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
1043 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
1044 pMgmt->eCurrState = WMAC_STATE_ASSOC;
1045 BSSvUpdateAPNode((void *)pDevice, sFrame.pwCapInfo, sFrame.pSuppRates, sFrame.pExtSuppRates);
1046 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1047 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
1048 pDevice->bLinkPass = true;
1049 pDevice->uBBVGADiffCount = 0;
1050 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1051 if(skb_tailroom(pDevice->skb) <(sizeof(viawget_wpa_header)+pMgmt->sAssocInfo.AssocInfo.ResponseIELength+
1052 pMgmt->sAssocInfo.AssocInfo.RequestIELength)) { //data room not enough
1053 dev_kfree_skb(pDevice->skb);
1054 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1056 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1057 wpahdr->type = VIAWGET_ASSOC_MSG;
1058 wpahdr->resp_ie_len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
1059 wpahdr->req_ie_len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1060 memcpy(pDevice->skb->data + sizeof(viawget_wpa_header), pMgmt->sAssocInfo.abyIEs, wpahdr->req_ie_len);
1061 memcpy(pDevice->skb->data + sizeof(viawget_wpa_header) + wpahdr->req_ie_len,
1062 pbyIEs,
1063 wpahdr->resp_ie_len
1065 skb_put(pDevice->skb, sizeof(viawget_wpa_header) + wpahdr->resp_ie_len + wpahdr->req_ie_len);
1066 pDevice->skb->dev = pDevice->wpadev;
1067 skb_reset_mac_header(pDevice->skb);
1068 pDevice->skb->pkt_type = PACKET_HOST;
1069 pDevice->skb->protocol = htons(ETH_P_802_2);
1070 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1071 netif_rx(pDevice->skb);
1072 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1075 //2008-0409-07, <Add> by Einsn Liu
1076 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1077 //if(pDevice->bWPADevEnable == true)
1079 unsigned char buf[512];
1080 size_t len;
1081 union iwreq_data wrqu;
1082 int we_event;
1084 memset(buf, 0, 512);
1086 len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1087 if(len) {
1088 memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
1089 memset(&wrqu, 0, sizeof (wrqu));
1090 wrqu.data.length = len;
1091 we_event = IWEVASSOCREQIE;
1092 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
1095 memset(buf, 0, 512);
1096 len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
1098 if(len) {
1099 memcpy(buf, pbyIEs, len);
1100 memset(&wrqu, 0, sizeof (wrqu));
1101 wrqu.data.length = len;
1102 we_event = IWEVASSOCRESPIE;
1103 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
1107 memset(&wrqu, 0, sizeof (wrqu));
1108 memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
1109 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1110 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1112 #endif //#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1113 //End Add -- //2008-0409-07, <Add> by Einsn Liu
1115 else {
1116 if (bReAssocType) {
1117 pMgmt->eCurrState = WMAC_STATE_IDLE;
1119 else {
1120 // jump back to the auth state and indicate the error
1121 pMgmt->eCurrState = WMAC_STATE_AUTH;
1123 s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
1128 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1129 //need clear flags related to Networkmanager
1131 pDevice->bwextcount = 0;
1132 pDevice->bWPASuppWextEnabled = false;
1133 #endif
1136 if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
1137 timer_expire(pDevice->sTimerCommand, 0);
1138 return;
1145 * Routine Description:
1146 * Start the station authentication procedure. Namely, send an
1147 * authentication frame to the AP.
1149 * Return Value:
1150 * None.
1154 void
1155 vMgrAuthenBeginSta(
1156 void *hDeviceContext,
1157 PSMgmtObject pMgmt,
1158 PCMD_STATUS pStatus
1161 PSDevice pDevice = (PSDevice)hDeviceContext;
1162 WLAN_FR_AUTHEN sFrame;
1163 PSTxMgmtPacket pTxPacket = NULL;
1165 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1166 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1167 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1168 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1169 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1170 vMgrEncodeAuthen(&sFrame);
1171 /* insert values */
1172 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1174 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1175 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
1177 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
1178 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1179 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1180 if (pMgmt->bShareKeyAlgorithm)
1181 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
1182 else
1183 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
1185 *(sFrame.pwAuthSequence) = cpu_to_le16(1);
1186 /* Adjust the length fields */
1187 pTxPacket->cbMPDULen = sFrame.len;
1188 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1190 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
1191 if (*pStatus == CMD_STATUS_PENDING){
1192 pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
1193 *pStatus = CMD_STATUS_SUCCESS;
1196 return ;
1203 * Routine Description:
1204 * Start the station(AP) deauthentication procedure. Namely, send an
1205 * deauthentication frame to the AP or Sta.
1207 * Return Value:
1208 * None.
1212 void
1213 vMgrDeAuthenBeginSta(
1214 void *hDeviceContext,
1215 PSMgmtObject pMgmt,
1216 unsigned char *abyDestAddress,
1217 unsigned short wReason,
1218 PCMD_STATUS pStatus
1221 PSDevice pDevice = (PSDevice)hDeviceContext;
1222 WLAN_FR_DEAUTHEN sFrame;
1223 PSTxMgmtPacket pTxPacket = NULL;
1226 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1227 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN);
1228 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1229 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1230 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
1231 vMgrEncodeDeauthen(&sFrame);
1232 /* insert values */
1233 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1235 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1236 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
1239 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
1240 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1241 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1243 *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
1244 /* Adjust the length fields */
1245 pTxPacket->cbMPDULen = sFrame.len;
1246 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1248 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
1249 if (*pStatus == CMD_STATUS_PENDING){
1250 *pStatus = CMD_STATUS_SUCCESS;
1254 return ;
1260 * Routine Description:
1261 * Handle incoming authentication frames.
1263 * Return Value:
1264 * None.
1268 static
1269 void
1270 s_vMgrRxAuthentication(
1271 PSDevice pDevice,
1272 PSMgmtObject pMgmt,
1273 PSRxMgmtPacket pRxPacket
1276 WLAN_FR_AUTHEN sFrame;
1278 // we better be an AP or a STA in AUTHPENDING otherwise ignore
1279 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
1280 pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
1281 return;
1284 // decode the frame
1285 sFrame.len = pRxPacket->cbMPDULen;
1286 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1287 vMgrDecodeAuthen(&sFrame);
1288 switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
1289 case 1:
1290 //AP funciton
1291 s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
1292 break;
1293 case 2:
1294 s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
1295 break;
1296 case 3:
1297 //AP funciton
1298 s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
1299 break;
1300 case 4:
1301 s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
1302 break;
1303 default:
1304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
1305 cpu_to_le16((*(sFrame.pwAuthSequence))));
1306 break;
1308 return;
1315 * Routine Description:
1316 * Handles incoming authen frames with sequence 1. Currently
1317 * assumes we're an AP. So far, no one appears to use authentication
1318 * in Ad-Hoc mode.
1320 * Return Value:
1321 * None.
1326 static
1327 void
1328 s_vMgrRxAuthenSequence_1(
1329 PSDevice pDevice,
1330 PSMgmtObject pMgmt,
1331 PWLAN_FR_AUTHEN pFrame
1334 PSTxMgmtPacket pTxPacket = NULL;
1335 unsigned int uNodeIndex;
1336 WLAN_FR_AUTHEN sFrame;
1337 PSKeyItem pTransmitKey;
1339 // Insert a Node entry
1340 if (!BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1341 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
1342 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2,
1343 WLAN_ADDR_LEN);
1346 if (pMgmt->bShareKeyAlgorithm) {
1347 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
1348 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
1350 else {
1351 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1354 // send auth reply
1355 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1356 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1357 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1358 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1359 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1360 // format buffer structure
1361 vMgrEncodeAuthen(&sFrame);
1362 // insert values
1363 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1365 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1366 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1367 WLAN_SET_FC_ISWEP(0)
1369 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1370 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1371 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1372 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1373 *(sFrame.pwAuthSequence) = cpu_to_le16(2);
1375 if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
1376 if (pMgmt->bShareKeyAlgorithm)
1377 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1378 else
1379 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1381 else {
1382 if (pMgmt->bShareKeyAlgorithm)
1383 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1384 else
1385 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1388 if (pMgmt->bShareKeyAlgorithm &&
1389 (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
1391 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1392 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1393 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1394 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1395 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1396 // get group key
1397 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
1398 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1399 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1401 memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
1404 /* Adjust the length fields */
1405 pTxPacket->cbMPDULen = sFrame.len;
1406 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1407 // send the frame
1408 if (pDevice->bEnableHostapd) {
1409 return;
1411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
1412 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1413 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
1415 return;
1422 * Routine Description:
1423 * Handles incoming auth frames with sequence number 2. Currently
1424 * assumes we're a station.
1427 * Return Value:
1428 * None.
1432 static
1433 void
1434 s_vMgrRxAuthenSequence_2(
1435 PSDevice pDevice,
1436 PSMgmtObject pMgmt,
1437 PWLAN_FR_AUTHEN pFrame
1440 WLAN_FR_AUTHEN sFrame;
1441 PSTxMgmtPacket pTxPacket = NULL;
1444 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
1446 case WLAN_AUTH_ALG_OPENSYSTEM:
1447 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1448 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
1449 pMgmt->eCurrState = WMAC_STATE_AUTH;
1450 timer_expire(pDevice->sTimerCommand, 0);
1452 else {
1453 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
1454 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1455 pMgmt->eCurrState = WMAC_STATE_IDLE;
1457 if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1458 // spin_unlock_irq(&pDevice->lock);
1459 // vCommandTimerWait((void *)pDevice, 0);
1460 // spin_lock_irq(&pDevice->lock);
1463 break;
1465 case WLAN_AUTH_ALG_SHAREDKEY:
1467 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1468 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1469 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1470 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1471 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1472 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1473 // format buffer structure
1474 vMgrEncodeAuthen(&sFrame);
1475 // insert values
1476 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1478 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1479 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1480 WLAN_SET_FC_ISWEP(1)
1482 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1483 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1484 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1485 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1486 *(sFrame.pwAuthSequence) = cpu_to_le16(3);
1487 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1488 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1489 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1490 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1491 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1492 memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
1493 // Adjust the length fields
1494 pTxPacket->cbMPDULen = sFrame.len;
1495 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1496 // send the frame
1497 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
1500 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
1502 else {
1503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
1504 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1505 // spin_unlock_irq(&pDevice->lock);
1506 // vCommandTimerWait((void *)pDevice, 0);
1507 // spin_lock_irq(&pDevice->lock);
1509 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1511 break;
1512 default:
1513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
1514 break;
1516 return;
1523 * Routine Description:
1524 * Handles incoming authen frames with sequence 3. Currently
1525 * assumes we're an AP. This function assumes the frame has
1526 * already been successfully decrypted.
1529 * Return Value:
1530 * None.
1534 static
1535 void
1536 s_vMgrRxAuthenSequence_3(
1537 PSDevice pDevice,
1538 PSMgmtObject pMgmt,
1539 PWLAN_FR_AUTHEN pFrame
1542 PSTxMgmtPacket pTxPacket = NULL;
1543 unsigned int uStatusCode = 0 ;
1544 unsigned int uNodeIndex = 0;
1545 WLAN_FR_AUTHEN sFrame;
1547 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1548 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1549 goto reply;
1551 if (BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1552 if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
1553 uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
1554 goto reply;
1556 if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
1557 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1558 goto reply;
1561 else {
1562 uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
1563 goto reply;
1566 if (uNodeIndex) {
1567 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1568 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
1570 uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
1571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
1573 reply:
1574 // send auth reply
1575 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1576 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1577 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1578 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1579 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1580 // format buffer structure
1581 vMgrEncodeAuthen(&sFrame);
1582 /* insert values */
1583 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1585 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1586 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1587 WLAN_SET_FC_ISWEP(0)
1589 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1590 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1591 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1592 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1593 *(sFrame.pwAuthSequence) = cpu_to_le16(4);
1594 *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
1596 /* Adjust the length fields */
1597 pTxPacket->cbMPDULen = sFrame.len;
1598 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1599 // send the frame
1600 if (pDevice->bEnableHostapd) {
1601 return;
1603 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1604 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
1606 return;
1614 * Routine Description:
1615 * Handles incoming authen frames with sequence 4
1618 * Return Value:
1619 * None.
1622 static
1623 void
1624 s_vMgrRxAuthenSequence_4(
1625 PSDevice pDevice,
1626 PSMgmtObject pMgmt,
1627 PWLAN_FR_AUTHEN pFrame
1631 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1632 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
1633 pMgmt->eCurrState = WMAC_STATE_AUTH;
1634 timer_expire(pDevice->sTimerCommand, 0);
1636 else{
1637 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
1638 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
1639 pMgmt->eCurrState = WMAC_STATE_IDLE;
1642 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1643 // spin_unlock_irq(&pDevice->lock);
1644 // vCommandTimerWait((void *)pDevice, 0);
1645 // spin_lock_irq(&pDevice->lock);
1652 * Routine Description:
1653 * Handles incoming disassociation frames
1656 * Return Value:
1657 * None.
1661 static
1662 void
1663 s_vMgrRxDisassociation(
1664 PSDevice pDevice,
1665 PSMgmtObject pMgmt,
1666 PSRxMgmtPacket pRxPacket
1669 WLAN_FR_DISASSOC sFrame;
1670 unsigned int uNodeIndex = 0;
1671 // CMD_STATUS CmdStatus;
1672 viawget_wpa_header *wpahdr;
1674 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1675 // if is acting an AP..
1676 // a STA is leaving this BSS..
1677 sFrame.len = pRxPacket->cbMPDULen;
1678 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1679 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1680 BSSvRemoveOneNode(pDevice, uNodeIndex);
1682 else {
1683 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
1686 else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
1687 sFrame.len = pRxPacket->cbMPDULen;
1688 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1689 vMgrDecodeDisassociation(&sFrame);
1690 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
1691 //TODO: do something let upper layer know or
1692 //try to send associate packet again because of inactivity timeout
1693 // if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
1694 // vMgrReAssocBeginSta((PSDevice)pDevice, pMgmt, &CmdStatus);
1695 // }
1696 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1697 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1698 wpahdr->type = VIAWGET_DISASSOC_MSG;
1699 wpahdr->resp_ie_len = 0;
1700 wpahdr->req_ie_len = 0;
1701 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1702 pDevice->skb->dev = pDevice->wpadev;
1703 skb_reset_mac_header(pDevice->skb);
1705 pDevice->skb->pkt_type = PACKET_HOST;
1706 pDevice->skb->protocol = htons(ETH_P_802_2);
1707 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1708 netif_rx(pDevice->skb);
1709 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1712 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1713 // if(pDevice->bWPASuppWextEnabled == true)
1715 union iwreq_data wrqu;
1716 memset(&wrqu, 0, sizeof (wrqu));
1717 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1718 printk("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1719 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1721 #endif
1723 /* else, ignore it */
1725 return;
1731 * Routine Description:
1732 * Handles incoming deauthentication frames
1735 * Return Value:
1736 * None.
1740 static
1741 void
1742 s_vMgrRxDeauthentication(
1743 PSDevice pDevice,
1744 PSMgmtObject pMgmt,
1745 PSRxMgmtPacket pRxPacket
1748 WLAN_FR_DEAUTHEN sFrame;
1749 unsigned int uNodeIndex = 0;
1750 viawget_wpa_header *wpahdr;
1753 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1754 //Todo:
1755 // if is acting an AP..
1756 // a STA is leaving this BSS..
1757 sFrame.len = pRxPacket->cbMPDULen;
1758 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1759 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1760 BSSvRemoveOneNode(pDevice, uNodeIndex);
1762 else {
1763 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
1766 else {
1767 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
1768 sFrame.len = pRxPacket->cbMPDULen;
1769 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1770 vMgrDecodeDeauthen(&sFrame);
1771 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
1772 // TODO: update BSS list for specific BSSID if pre-authentication case
1773 if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID)) {
1774 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
1775 pMgmt->sNodeDBTable[0].bActive = false;
1776 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1777 pMgmt->eCurrState = WMAC_STATE_IDLE;
1778 netif_stop_queue(pDevice->dev);
1779 pDevice->bLinkPass = false;
1783 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1784 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1785 wpahdr->type = VIAWGET_DISASSOC_MSG;
1786 wpahdr->resp_ie_len = 0;
1787 wpahdr->req_ie_len = 0;
1788 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1789 pDevice->skb->dev = pDevice->wpadev;
1790 skb_reset_mac_header(pDevice->skb);
1791 pDevice->skb->pkt_type = PACKET_HOST;
1792 pDevice->skb->protocol = htons(ETH_P_802_2);
1793 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1794 netif_rx(pDevice->skb);
1795 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1798 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1799 // if(pDevice->bWPASuppWextEnabled == true)
1801 union iwreq_data wrqu;
1802 memset(&wrqu, 0, sizeof (wrqu));
1803 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1804 PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
1805 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1807 #endif
1810 /* else, ignore it. TODO: IBSS authentication service
1811 would be implemented here */
1813 return;
1817 //2008-8-4 <add> by chester
1820 * Routine Description:
1821 * check if current channel is match ZoneType.
1822 *for USA:1~11;
1823 * Japan:1~13;
1824 * Europe:1~13
1825 * Return Value:
1826 * True:exceed;
1827 * False:normal case
1829 static bool
1830 ChannelExceedZoneType(
1831 PSDevice pDevice,
1832 unsigned char byCurrChannel
1835 bool exceed=false;
1837 switch(pDevice->byZoneType) {
1838 case 0x00: //USA:1~11
1839 if((byCurrChannel<1) ||(byCurrChannel>11))
1840 exceed = true;
1841 break;
1842 case 0x01: //Japan:1~13
1843 case 0x02: //Europe:1~13
1844 if((byCurrChannel<1) ||(byCurrChannel>13))
1845 exceed = true;
1846 break;
1847 default: //reserve for other zonetype
1848 break;
1851 return exceed;
1857 * Routine Description:
1858 * Handles and analysis incoming beacon frames.
1861 * Return Value:
1862 * None.
1866 static
1867 void
1868 s_vMgrRxBeacon(
1869 PSDevice pDevice,
1870 PSMgmtObject pMgmt,
1871 PSRxMgmtPacket pRxPacket,
1872 bool bInScan
1876 PKnownBSS pBSSList;
1877 WLAN_FR_BEACON sFrame;
1878 QWORD qwTSFOffset;
1879 bool bIsBSSIDEqual = false;
1880 bool bIsSSIDEqual = false;
1881 bool bTSFLargeDiff = false;
1882 bool bTSFOffsetPostive = false;
1883 bool bUpdateTSF = false;
1884 bool bIsAPBeacon = false;
1885 bool bIsChannelEqual = false;
1886 unsigned int uLocateByteIndex;
1887 unsigned char byTIMBitOn = 0;
1888 unsigned short wAIDNumber = 0;
1889 unsigned int uNodeIndex;
1890 QWORD qwTimestamp, qwLocalTSF;
1891 QWORD qwCurrTSF;
1892 unsigned short wStartIndex = 0;
1893 unsigned short wAIDIndex = 0;
1894 unsigned char byCurrChannel = pRxPacket->byRxChannel;
1895 ERPObject sERP;
1896 unsigned int uRateLen = WLAN_RATES_MAXLEN;
1897 bool bChannelHit = false;
1898 bool bUpdatePhyParameter = false;
1899 unsigned char byIEChannel = 0;
1902 memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
1903 sFrame.len = pRxPacket->cbMPDULen;
1904 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1906 // decode the beacon frame
1907 vMgrDecodeBeacon(&sFrame);
1909 if ((sFrame.pwBeaconInterval == 0) ||
1910 (sFrame.pwCapInfo == 0) ||
1911 (sFrame.pSSID == 0) ||
1912 (sFrame.pSuppRates == 0) ) {
1913 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
1914 return;
1918 if (sFrame.pDSParms != NULL) {
1919 if (byCurrChannel > CB_MAX_CHANNEL_24G) {
1920 // channel remapping to
1921 byIEChannel = get_channel_mapping(pDevice, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
1922 } else {
1923 byIEChannel = sFrame.pDSParms->byCurrChannel;
1925 if (byCurrChannel != byIEChannel) {
1926 // adjust channel info. bcs we rcv adjcent channel pakckets
1927 bChannelHit = false;
1928 byCurrChannel = byIEChannel;
1930 } else {
1931 // no DS channel info
1932 bChannelHit = true;
1934 //2008-0730-01<Add>by MikeLiu
1935 if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
1936 return;
1938 if (sFrame.pERP != NULL) {
1939 sERP.byERP = sFrame.pERP->byContext;
1940 sERP.bERPExist = true;
1942 } else {
1943 sERP.bERPExist = false;
1944 sERP.byERP = 0;
1947 pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
1948 if (pBSSList == NULL) {
1949 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
1950 BSSbInsertToBSSList((void *)pDevice,
1951 sFrame.pHdr->sA3.abyAddr3,
1952 *sFrame.pqwTimestamp,
1953 *sFrame.pwBeaconInterval,
1954 *sFrame.pwCapInfo,
1955 byCurrChannel,
1956 sFrame.pSSID,
1957 sFrame.pSuppRates,
1958 sFrame.pExtSuppRates,
1959 &sERP,
1960 sFrame.pRSN,
1961 sFrame.pRSNWPA,
1962 sFrame.pIE_Country,
1963 sFrame.pIE_Quiet,
1964 sFrame.len - WLAN_HDR_ADDR3_LEN,
1965 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
1966 (void *)pRxPacket
1969 else {
1970 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
1971 BSSbUpdateToBSSList((void *)pDevice,
1972 *sFrame.pqwTimestamp,
1973 *sFrame.pwBeaconInterval,
1974 *sFrame.pwCapInfo,
1975 byCurrChannel,
1976 bChannelHit,
1977 sFrame.pSSID,
1978 sFrame.pSuppRates,
1979 sFrame.pExtSuppRates,
1980 &sERP,
1981 sFrame.pRSN,
1982 sFrame.pRSNWPA,
1983 sFrame.pIE_Country,
1984 sFrame.pIE_Quiet,
1985 pBSSList,
1986 sFrame.len - WLAN_HDR_ADDR3_LEN,
1987 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
1988 (void *)pRxPacket
1993 if (bInScan) {
1994 return;
1997 if(byCurrChannel == (unsigned char)pMgmt->uCurrChannel)
1998 bIsChannelEqual = true;
2000 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
2002 // if rx beacon without ERP field
2003 if (sERP.bERPExist) {
2004 if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
2005 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
2006 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
2009 else {
2010 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
2011 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
2014 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2015 if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
2016 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
2017 if(!sERP.bERPExist)
2018 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
2021 // set to MAC&BBP
2022 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)){
2023 if (!pDevice->bProtectMode) {
2024 MACvEnableProtectMD(pDevice->PortOffset);
2025 pDevice->bProtectMode = true;
2031 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
2032 return;
2034 // check if BSSID the same
2035 if (memcmp(sFrame.pHdr->sA3.abyAddr3,
2036 pMgmt->abyCurrBSSID,
2037 WLAN_BSSID_LEN) == 0) {
2039 bIsBSSIDEqual = true;
2041 // 2008-05-21 <add> by Richardtai
2042 pDevice->uCurrRSSI = pRxPacket->uRSSI;
2043 pDevice->byCurrSQ = pRxPacket->bySQ;
2045 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
2046 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2047 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
2050 // check if SSID the same
2051 if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
2052 if (memcmp(sFrame.pSSID->abySSID,
2053 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
2054 sFrame.pSSID->len
2055 ) == 0) {
2056 bIsSSIDEqual = true;
2060 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
2061 (bIsBSSIDEqual == true) &&
2062 (bIsSSIDEqual == true) &&
2063 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2064 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2065 // add state check to prevent reconnect fail since we'll receive Beacon
2067 bIsAPBeacon = true;
2069 if (pBSSList != NULL) {
2071 // Compare PHY paramater setting
2072 if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
2073 bUpdatePhyParameter = true;
2074 pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
2076 if (sFrame.pERP != NULL) {
2077 if ((sFrame.pERP->byElementID == WLAN_EID_ERP) &&
2078 (pMgmt->byERPContext != sFrame.pERP->byContext)) {
2079 bUpdatePhyParameter = true;
2080 pMgmt->byERPContext = sFrame.pERP->byContext;
2084 // Basic Rate Set may change dynamiclly
2086 if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
2087 uRateLen = WLAN_RATES_MAXLEN_11B;
2089 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
2090 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2091 uRateLen);
2092 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
2093 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
2094 uRateLen);
2095 RATEvParseMaxRate( (void *)pDevice,
2096 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2097 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
2098 true,
2099 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
2100 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
2101 &(pMgmt->sNodeDBTable[0].wSuppRate),
2102 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
2103 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
2105 #ifdef PLICE_DEBUG
2106 //printk("RxBeacon:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
2107 #endif
2108 if (bUpdatePhyParameter == true) {
2109 CARDbSetPhyParameter( pMgmt->pAdapter,
2110 pMgmt->eCurrentPHYMode,
2111 pMgmt->wCurrCapInfo,
2112 pMgmt->byERPContext,
2113 pMgmt->abyCurrSuppRates,
2114 pMgmt->abyCurrExtSuppRates
2117 if (sFrame.pIE_PowerConstraint != NULL) {
2118 CARDvSetPowerConstraint(pMgmt->pAdapter,
2119 (unsigned char) pBSSList->uChannel,
2120 sFrame.pIE_PowerConstraint->byPower
2123 if (sFrame.pIE_CHSW != NULL) {
2124 CARDbChannelSwitch( pMgmt->pAdapter,
2125 sFrame.pIE_CHSW->byMode,
2126 get_channel_mapping(pMgmt->pAdapter, sFrame.pIE_CHSW->byMode, pMgmt->eCurrentPHYMode),
2127 sFrame.pIE_CHSW->byCount
2130 } else if (bIsChannelEqual == false) {
2131 set_channel(pMgmt->pAdapter, pBSSList->uChannel);
2136 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
2137 // check if CF field exisit
2138 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
2139 if (sFrame.pCFParms->wCFPDurRemaining > 0) {
2140 // TODO: deal with CFP period to set NAV
2144 HIDWORD(qwTimestamp) = cpu_to_le32(HIDWORD(*sFrame.pqwTimestamp));
2145 LODWORD(qwTimestamp) = cpu_to_le32(LODWORD(*sFrame.pqwTimestamp));
2146 HIDWORD(qwLocalTSF) = HIDWORD(pRxPacket->qwLocalTSF);
2147 LODWORD(qwLocalTSF) = LODWORD(pRxPacket->qwLocalTSF);
2149 // check if beacon TSF larger or small than our local TSF
2150 if (HIDWORD(qwTimestamp) == HIDWORD(qwLocalTSF)) {
2151 if (LODWORD(qwTimestamp) >= LODWORD(qwLocalTSF)) {
2152 bTSFOffsetPostive = true;
2154 else {
2155 bTSFOffsetPostive = false;
2158 else if (HIDWORD(qwTimestamp) > HIDWORD(qwLocalTSF)) {
2159 bTSFOffsetPostive = true;
2161 else if (HIDWORD(qwTimestamp) < HIDWORD(qwLocalTSF)) {
2162 bTSFOffsetPostive = false;
2165 if (bTSFOffsetPostive) {
2166 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
2168 else {
2169 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
2172 if (HIDWORD(qwTSFOffset) != 0 ||
2173 (LODWORD(qwTSFOffset) > TRIVIAL_SYNC_DIFFERENCE )) {
2174 bTSFLargeDiff = true;
2178 // if infra mode
2179 if (bIsAPBeacon == true) {
2181 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
2182 if (bTSFLargeDiff)
2183 bUpdateTSF = true;
2185 if ((pDevice->bEnablePSMode == true) &&(sFrame.pTIM != 0)) {
2187 // deal with DTIM, analysis TIM
2188 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
2189 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
2190 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
2191 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
2193 // check if AID in TIM field bit on
2194 // wStartIndex = N1
2195 wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
2196 // AIDIndex = N2
2197 wAIDIndex = (wAIDNumber >> 3);
2198 if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
2199 uLocateByteIndex = wAIDIndex - wStartIndex;
2200 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
2201 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
2202 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
2203 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
2205 else {
2206 pMgmt->bInTIM = false;
2209 else {
2210 pMgmt->bInTIM = false;
2213 if (pMgmt->bInTIM ||
2214 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
2215 pMgmt->bInTIMWake = true;
2216 // send out ps-poll packet
2217 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:In TIM\n");
2218 if (pMgmt->bInTIM) {
2219 PSvSendPSPOLL((PSDevice)pDevice);
2220 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:PS-POLL sent..\n");
2224 else {
2225 pMgmt->bInTIMWake = false;
2226 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
2227 if (pDevice->bPWBitOn == false) {
2228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
2229 if (PSbSendNullPacket(pDevice))
2230 pDevice->bPWBitOn = true;
2232 if(PSbConsiderPowerDown(pDevice, false, false)) {
2233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
2240 // if adhoc mode
2241 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
2242 if (bIsBSSIDEqual) {
2243 // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
2244 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
2245 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2247 // adhoc mode:TSF updated only when beacon larger then local TSF
2248 if (bTSFLargeDiff && bTSFOffsetPostive &&
2249 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
2250 bUpdateTSF = true;
2252 // During dpc, already in spinlocked.
2253 if (BSSDBbIsSTAInNodeDB(pMgmt, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
2255 // Update the STA, (Techically the Beacons of all the IBSS nodes
2256 // should be identical, but that's not happening in practice.
2257 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2258 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2259 WLAN_RATES_MAXLEN_11B);
2260 RATEvParseMaxRate( (void *)pDevice,
2261 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2262 NULL,
2263 true,
2264 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2265 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2266 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
2267 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
2268 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
2270 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
2271 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
2272 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
2274 else {
2275 // Todo, initial Node content
2276 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
2278 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2279 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2280 WLAN_RATES_MAXLEN_11B);
2281 RATEvParseMaxRate( (void *)pDevice,
2282 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2283 NULL,
2284 true,
2285 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2286 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2287 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
2288 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
2289 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
2292 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
2293 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
2294 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
2295 #ifdef PLICE_DEBUG
2296 //if (uNodeIndex == 0)
2298 printk("s_vMgrRxBeacon:TxDataRate is %d,Index is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate,uNodeIndex);
2300 #endif
2302 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
2303 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
2304 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
2308 // if other stations jointed, indicate connect to upper layer..
2309 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
2310 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
2311 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2312 pDevice->bLinkPass = true;
2313 if (netif_queue_stopped(pDevice->dev)){
2314 netif_wake_queue(pDevice->dev);
2316 pMgmt->sNodeDBTable[0].bActive = true;
2317 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2321 else if (bIsSSIDEqual) {
2323 // See other adhoc sta with the same SSID but BSSID is different.
2324 // adpot this vars only when TSF larger then us.
2325 if (bTSFLargeDiff && bTSFOffsetPostive) {
2326 // we don't support ATIM under adhoc mode
2327 // if ( sFrame.pIBSSParms->wATIMWindow == 0) {
2328 // adpot this vars
2329 // TODO: check sFrame cap if privacy on, and support rate syn
2330 memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
2331 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
2332 pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
2333 pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
2334 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2335 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2336 WLAN_RATES_MAXLEN_11B);
2337 // set HW beacon interval and re-synchronizing....
2338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
2339 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, pMgmt->wCurrBeaconPeriod);
2340 CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, qwLocalTSF);
2341 CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
2342 // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
2343 MACvWriteBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
2345 CARDbSetPhyParameter ( pMgmt->pAdapter,
2346 pMgmt->eCurrentPHYMode,
2347 pMgmt->wCurrCapInfo,
2348 pMgmt->byERPContext,
2349 pMgmt->abyCurrSuppRates,
2350 pMgmt->abyCurrExtSuppRates);
2353 // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
2354 // set highest basic rate
2355 // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
2356 // Prepare beacon frame
2357 bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
2358 // }
2362 // endian issue ???
2363 // Update TSF
2364 if (bUpdateTSF) {
2365 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2366 CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
2367 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2368 CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
2371 return;
2378 * Routine Description:
2379 * Instructs the hw to create a bss using the supplied
2380 * attributes. Note that this implementation only supports Ad-Hoc
2381 * BSS creation.
2384 * Return Value:
2385 * CMD_STATUS
2388 void
2389 vMgrCreateOwnIBSS(
2390 void *hDeviceContext,
2391 PCMD_STATUS pStatus
2394 PSDevice pDevice = (PSDevice)hDeviceContext;
2395 PSMgmtObject pMgmt = pDevice->pMgmt;
2396 unsigned short wMaxBasicRate;
2397 unsigned short wMaxSuppRate;
2398 unsigned char byTopCCKBasicRate;
2399 unsigned char byTopOFDMBasicRate;
2400 QWORD qwCurrTSF;
2401 unsigned int ii;
2402 unsigned char abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60};
2403 unsigned char abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
2404 unsigned char abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2405 unsigned short wSuppRate;
2407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
2409 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2410 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
2411 (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
2412 (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
2413 // encryption mode error
2414 *pStatus = CMD_STATUS_FAILURE;
2415 return;
2419 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2420 pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
2422 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2423 pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
2424 } else {
2425 if (pDevice->byBBType == BB_TYPE_11G)
2426 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2427 if (pDevice->byBBType == BB_TYPE_11B)
2428 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2429 if (pDevice->byBBType == BB_TYPE_11A)
2430 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2433 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
2434 pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
2435 pMgmt->abyCurrExtSuppRates[1] = 0;
2436 for (ii = 0; ii < 4; ii++)
2437 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2438 } else {
2439 pMgmt->abyCurrSuppRates[1] = 8;
2440 pMgmt->abyCurrExtSuppRates[1] = 0;
2441 for (ii = 0; ii < 8; ii++)
2442 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2446 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2447 pMgmt->abyCurrSuppRates[1] = 8;
2448 pMgmt->abyCurrExtSuppRates[1] = 4;
2449 for (ii = 0; ii < 4; ii++)
2450 pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
2451 for (ii = 4; ii < 8; ii++)
2452 pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
2453 for (ii = 0; ii < 4; ii++)
2454 pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
2458 // Disable Protect Mode
2459 pDevice->bProtectMode = 0;
2460 MACvDisableProtectMD(pDevice->PortOffset);
2462 pDevice->bBarkerPreambleMd = 0;
2463 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
2465 // Kyle Test 2003.11.04
2467 // set HW beacon interval
2468 if (pMgmt->wIBSSBeaconPeriod == 0)
2469 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
2472 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2473 // clear TSF counter
2474 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
2475 // enable TSF counter
2476 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2478 // set Next TBTT
2479 CARDvSetFirstNextTBTT(pDevice->PortOffset, pMgmt->wIBSSBeaconPeriod);
2481 pMgmt->uIBSSChannel = pDevice->uChannel;
2483 if (pMgmt->uIBSSChannel == 0)
2484 pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
2487 // set basic rate
2489 RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2490 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
2491 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2492 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2495 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2496 pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
2499 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2500 memcpy(pMgmt->abyIBSSDFSOwner, pDevice->abyCurrentNetAddr, 6);
2501 pMgmt->byIBSSDFSRecovery = 10;
2502 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2505 // Adopt pre-configured IBSS vars to current vars
2506 pMgmt->eCurrState = WMAC_STATE_STARTED;
2507 pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
2508 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2509 pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
2510 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
2511 pDevice->uCurrRSSI = 0;
2512 pDevice->byCurrSQ = 0;
2513 //memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
2514 // ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
2515 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2516 memcpy(pMgmt->abyCurrSSID,
2517 pMgmt->abyDesireSSID,
2518 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
2521 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2522 // AP mode BSSID = MAC addr
2523 memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2524 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:%02x-%02x-%02x-%02x-%02x-%02x \n",
2525 pMgmt->abyCurrBSSID[0],
2526 pMgmt->abyCurrBSSID[1],
2527 pMgmt->abyCurrBSSID[2],
2528 pMgmt->abyCurrBSSID[3],
2529 pMgmt->abyCurrBSSID[4],
2530 pMgmt->abyCurrBSSID[5]
2534 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2536 // BSSID selected must be randomized as spec 11.1.3
2537 pMgmt->abyCurrBSSID[5] = (unsigned char) (LODWORD(qwCurrTSF)& 0x000000ff);
2538 pMgmt->abyCurrBSSID[4] = (unsigned char)((LODWORD(qwCurrTSF)& 0x0000ff00) >> 8);
2539 pMgmt->abyCurrBSSID[3] = (unsigned char)((LODWORD(qwCurrTSF)& 0x00ff0000) >> 16);
2540 pMgmt->abyCurrBSSID[2] = (unsigned char)((LODWORD(qwCurrTSF)& 0x00000ff0) >> 4);
2541 pMgmt->abyCurrBSSID[1] = (unsigned char)((LODWORD(qwCurrTSF)& 0x000ff000) >> 12);
2542 pMgmt->abyCurrBSSID[0] = (unsigned char)((LODWORD(qwCurrTSF)& 0x0ff00000) >> 20);
2543 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2544 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2545 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
2546 pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
2547 pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
2548 pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
2549 pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
2550 pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
2553 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:%02x-%02x-%02x-%02x-%02x-%02x \n",
2554 pMgmt->abyCurrBSSID[0],
2555 pMgmt->abyCurrBSSID[1],
2556 pMgmt->abyCurrBSSID[2],
2557 pMgmt->abyCurrBSSID[3],
2558 pMgmt->abyCurrBSSID[4],
2559 pMgmt->abyCurrBSSID[5]
2563 // Set Capability Info
2564 pMgmt->wCurrCapInfo = 0;
2566 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2567 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
2568 pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
2569 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2572 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2573 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
2576 if (pDevice->bEncryptionEnable) {
2577 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
2578 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2579 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2580 pMgmt->byCSSPK = KEY_CTL_CCMP;
2581 pMgmt->byCSSGK = KEY_CTL_CCMP;
2582 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2583 pMgmt->byCSSPK = KEY_CTL_TKIP;
2584 pMgmt->byCSSGK = KEY_CTL_TKIP;
2585 } else {
2586 pMgmt->byCSSPK = KEY_CTL_NONE;
2587 pMgmt->byCSSGK = KEY_CTL_WEP;
2589 } else {
2590 pMgmt->byCSSPK = KEY_CTL_WEP;
2591 pMgmt->byCSSGK = KEY_CTL_WEP;
2595 pMgmt->byERPContext = 0;
2597 // memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
2599 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2600 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
2601 } else {
2602 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
2605 CARDbSetPhyParameter( pMgmt->pAdapter,
2606 pMgmt->eCurrentPHYMode,
2607 pMgmt->wCurrCapInfo,
2608 pMgmt->byERPContext,
2609 pMgmt->abyCurrSuppRates,
2610 pMgmt->abyCurrExtSuppRates
2613 CARDbSetBeaconPeriod(pMgmt->pAdapter, pMgmt->wIBSSBeaconPeriod);
2614 // set channel and clear NAV
2615 set_channel(pMgmt->pAdapter, pMgmt->uIBSSChannel);
2616 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2618 if (CARDbIsShortPreamble(pMgmt->pAdapter)) {
2619 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
2620 } else {
2621 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
2624 if ((pMgmt->b11hEnable == true) &&
2625 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
2626 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
2627 } else {
2628 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SPECTRUMMNG(1));
2631 pMgmt->eCurrState = WMAC_STATE_STARTED;
2632 // Prepare beacon to send
2633 if (bMgrPrepareBeaconToSend((void *)pDevice, pMgmt)) {
2634 *pStatus = CMD_STATUS_SUCCESS;
2637 return ;
2644 * Routine Description:
2645 * Instructs wmac to join a bss using the supplied attributes.
2646 * The arguments may the BSSID or SSID and the rest of the
2647 * attributes are obtained from the scan result of known bss list.
2650 * Return Value:
2651 * None.
2655 void
2656 vMgrJoinBSSBegin(
2657 void *hDeviceContext,
2658 PCMD_STATUS pStatus
2662 PSDevice pDevice = (PSDevice)hDeviceContext;
2663 PSMgmtObject pMgmt = pDevice->pMgmt;
2664 PKnownBSS pCurr = NULL;
2665 unsigned int ii, uu;
2666 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2667 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2668 PWLAN_IE_SSID pItemSSID;
2669 unsigned int uRateLen = WLAN_RATES_MAXLEN;
2670 unsigned short wMaxBasicRate = RATE_1M;
2671 unsigned short wMaxSuppRate = RATE_1M;
2672 unsigned short wSuppRate;
2673 unsigned char byTopCCKBasicRate = RATE_1M;
2674 unsigned char byTopOFDMBasicRate = RATE_1M;
2677 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
2678 if (pMgmt->sBSSList[ii].bActive == true)
2679 break;
2682 if (ii == MAX_BSS_NUM) {
2683 *pStatus = CMD_STATUS_RESOURCES;
2684 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
2685 return;
2688 // memset(pMgmt->abyDesireBSSID, 0, WLAN_BSSID_LEN);
2689 // Search known BSS list for prefer BSSID or SSID
2691 pCurr = BSSpSearchBSSList(pDevice,
2692 pMgmt->abyDesireBSSID,
2693 pMgmt->abyDesireSSID,
2694 pMgmt->eConfigPHYMode
2697 if (pCurr == NULL){
2698 *pStatus = CMD_STATUS_RESOURCES;
2699 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
2700 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
2701 return;
2704 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
2705 if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
2707 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA)||(pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2709 // patch for CISCO migration mode
2711 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2712 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
2713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2714 // encryption mode error
2715 pMgmt->eCurrState = WMAC_STATE_IDLE;
2716 return;
2718 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2719 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
2720 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2721 // encryption mode error
2722 pMgmt->eCurrState = WMAC_STATE_IDLE;
2723 return;
2729 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2730 //if(pDevice->bWPASuppWextEnabled == true)
2731 Encyption_Rebuild(pDevice, pCurr);
2732 #endif
2733 // Infrastructure BSS
2734 s_vMgrSynchBSS(pDevice,
2735 WMAC_MODE_ESS_STA,
2736 pCurr,
2737 pStatus
2740 if (*pStatus == CMD_STATUS_SUCCESS){
2742 // Adopt this BSS state vars in Mgmt Object
2743 pMgmt->uCurrChannel = pCurr->uChannel;
2745 memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2746 memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2748 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2749 uRateLen = WLAN_RATES_MAXLEN_11B;
2752 pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
2753 pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
2755 // Parse Support Rate IE
2756 pItemRates->byElementID = WLAN_EID_SUPP_RATES;
2757 pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2758 pItemRates,
2759 uRateLen);
2761 // Parse Extension Support Rate IE
2762 pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
2763 pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
2764 pItemExtRates,
2765 uRateLen);
2766 // Stuffing Rate IE
2767 if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
2768 for (ii = 0; ii < (unsigned int)(8 - pItemRates->len); ) {
2769 pItemRates->abyRates[pItemRates->len + ii] = pItemExtRates->abyRates[ii];
2770 ii ++;
2771 if (pItemExtRates->len <= ii)
2772 break;
2774 pItemRates->len += (unsigned char)ii;
2775 if (pItemExtRates->len - ii > 0) {
2776 pItemExtRates->len -= (unsigned char)ii;
2777 for (uu = 0; uu < pItemExtRates->len; uu ++) {
2778 pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
2780 } else {
2781 pItemExtRates->len = 0;
2785 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
2786 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2787 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2789 // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
2790 // TODO: deal with if wCapInfo the PS-Pollable is on.
2791 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2792 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2793 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2794 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2796 pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
2798 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2799 // Adopt BSS state in Adapter Device Object
2800 //pDevice->byOpMode = OP_MODE_INFRASTRUCTURE;
2801 // memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2803 // Add current BSS to Candidate list
2804 // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
2805 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
2806 bool bResult = bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
2807 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
2808 if (bResult == false) {
2809 vFlush_PMKID_Candidate((void *)pDevice);
2810 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 4\n");
2811 bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
2815 // Preamble type auto-switch: if AP can receive short-preamble cap,
2816 // we can turn on too.
2818 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
2822 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
2824 else {
2825 pMgmt->eCurrState = WMAC_STATE_IDLE;
2830 else {
2831 // ad-hoc mode BSS
2832 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2834 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2835 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
2836 // encryption mode error
2837 pMgmt->eCurrState = WMAC_STATE_IDLE;
2838 return;
2840 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2841 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
2842 // encryption mode error
2843 pMgmt->eCurrState = WMAC_STATE_IDLE;
2844 return;
2846 } else {
2847 // encryption mode error
2848 pMgmt->eCurrState = WMAC_STATE_IDLE;
2849 return;
2853 s_vMgrSynchBSS(pDevice,
2854 WMAC_MODE_IBSS_STA,
2855 pCurr,
2856 pStatus
2859 if (*pStatus == CMD_STATUS_SUCCESS){
2860 // Adopt this BSS state vars in Mgmt Object
2861 // TODO: check if CapInfo privacy on, but we don't..
2862 pMgmt->uCurrChannel = pCurr->uChannel;
2865 // Parse Support Rate IE
2866 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2867 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2868 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2869 WLAN_RATES_MAXLEN_11B);
2870 // set basic rate
2871 RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2872 NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2873 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2875 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
2876 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2877 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2878 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2879 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2880 // pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
2881 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
2882 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2884 pMgmt->eCurrState = WMAC_STATE_STARTED;
2885 // Adopt BSS state in Adapter Device Object
2886 //pDevice->byOpMode = OP_MODE_ADHOC;
2887 // pDevice->bLinkPass = true;
2888 // memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2890 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%02x-%02x-%02x-%02x-%02x-%02x \n",
2891 pMgmt->abyCurrBSSID[0],
2892 pMgmt->abyCurrBSSID[1],
2893 pMgmt->abyCurrBSSID[2],
2894 pMgmt->abyCurrBSSID[3],
2895 pMgmt->abyCurrBSSID[4],
2896 pMgmt->abyCurrBSSID[5]
2898 // Preamble type auto-switch: if AP can receive short-preamble cap,
2899 // and if registry setting is short preamble we can turn on too.
2901 // Prepare beacon
2902 bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
2904 else {
2905 pMgmt->eCurrState = WMAC_STATE_IDLE;
2908 return;
2915 * Routine Description:
2916 * Set HW to synchronize a specific BSS from known BSS list.
2919 * Return Value:
2920 * PCM_STATUS
2923 static
2924 void
2925 s_vMgrSynchBSS (
2926 PSDevice pDevice,
2927 unsigned int uBSSMode,
2928 PKnownBSS pCurr,
2929 PCMD_STATUS pStatus
2932 CARD_PHY_TYPE ePhyType = PHY_TYPE_11B;
2933 PSMgmtObject pMgmt = pDevice->pMgmt;
2934 // int ii;
2935 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
2936 unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
2937 unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
2938 //6M, 9M, 12M, 48M
2939 unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2940 unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
2943 *pStatus = CMD_STATUS_FAILURE;
2945 if (s_bCipherMatch(pCurr,
2946 pDevice->eEncryptionStatus,
2947 &(pMgmt->byCSSPK),
2948 &(pMgmt->byCSSGK)) == false) {
2949 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_bCipherMatch Fail .......\n");
2950 return;
2953 pMgmt->pCurrBSS = pCurr;
2955 // if previous mode is IBSS.
2956 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2957 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_BCNDMACTL, BEACON_READY);
2958 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2961 // Init the BSS informations
2962 pDevice->bCCK = true;
2963 pDevice->bProtectMode = false;
2964 MACvDisableProtectMD(pDevice->PortOffset);
2965 pDevice->bBarkerPreambleMd = false;
2966 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
2967 pDevice->bNonERPPresent = false;
2968 pDevice->byPreambleType = 0;
2969 pDevice->wBasicRate = 0;
2970 // Set Basic Rate
2971 CARDbAddBasicRate((void *)pDevice, RATE_1M);
2972 // calculate TSF offset
2973 // TSF Offset = Received Timestamp TSF - Marked Local's TSF
2974 CARDbUpdateTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
2976 CARDbSetBeaconPeriod(pDevice, pCurr->wBeaconInterval);
2978 // set Next TBTT
2979 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2980 CARDvSetFirstNextTBTT(pDevice->PortOffset, pCurr->wBeaconInterval);
2982 // set BSSID
2983 MACvWriteBSSIDAddress(pDevice->PortOffset, pCurr->abyBSSID);
2985 MACvReadBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
2987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = %02x-%02x-%02x=%02x-%02x-%02x\n",
2988 pMgmt->abyCurrBSSID[0],
2989 pMgmt->abyCurrBSSID[1],
2990 pMgmt->abyCurrBSSID[2],
2991 pMgmt->abyCurrBSSID[3],
2992 pMgmt->abyCurrBSSID[4],
2993 pMgmt->abyCurrBSSID[5]);
2995 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
2996 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11A) ||
2997 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
2998 ePhyType = PHY_TYPE_11A;
2999 } else {
3000 return;
3002 } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
3003 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11B) ||
3004 (pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
3005 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
3006 ePhyType = PHY_TYPE_11B;
3007 } else {
3008 return;
3010 } else {
3011 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
3012 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
3013 ePhyType = PHY_TYPE_11G;
3014 } else if (pMgmt->eConfigPHYMode == PHY_TYPE_11B) {
3015 ePhyType = PHY_TYPE_11B;
3016 } else {
3017 return;
3021 if (ePhyType == PHY_TYPE_11A) {
3022 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
3023 pMgmt->abyCurrExtSuppRates[1] = 0;
3024 } else if (ePhyType == PHY_TYPE_11B) {
3025 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
3026 pMgmt->abyCurrExtSuppRates[1] = 0;
3027 } else {
3028 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
3029 memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
3033 if (WLAN_GET_CAP_INFO_ESS(pCurr->wCapInfo)) {
3034 CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_INFRASTRUCTURE);
3035 // Add current BSS to Candidate list
3036 // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
3037 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3038 CARDbAdd_PMKID_Candidate(pMgmt->pAdapter, pMgmt->abyCurrBSSID, pCurr->sRSNCapObj.bRSNCapExist, pCurr->sRSNCapObj.wRSNCap);
3040 } else {
3041 CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_ADHOC);
3044 if (CARDbSetPhyParameter( pMgmt->pAdapter,
3045 ePhyType,
3046 pCurr->wCapInfo,
3047 pCurr->sERP.byERP,
3048 pMgmt->abyCurrSuppRates,
3049 pMgmt->abyCurrExtSuppRates
3050 ) != true) {
3051 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Phy Mode Fail [%d]\n", ePhyType);
3052 return;
3054 // set channel and clear NAV
3055 if (set_channel(pMgmt->pAdapter, pCurr->uChannel) == false) {
3056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
3057 return;
3061 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
3062 if (pCurr->ldBmMAX< pDevice->ldBmThreshold[ii]) {
3063 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
3064 break;
3068 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
3069 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] \n",
3070 (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
3071 printk("RSSI[%d] NewGain[%d] OldGain[%d] \n",
3072 (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
3073 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
3075 printk("ldBmMAX[%d] NewGain[%d] OldGain[%d] \n",
3076 (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
3078 pMgmt->uCurrChannel = pCurr->uChannel;
3079 pMgmt->eCurrentPHYMode = ePhyType;
3080 pMgmt->byERPContext = pCurr->sERP.byERP;
3081 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:Set to channel = [%d]\n", (int)pCurr->uChannel);
3084 *pStatus = CMD_STATUS_SUCCESS;
3087 return;
3090 //mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption
3091 // ,need reset eAuthenMode and eEncryptionStatus
3092 static void Encyption_Rebuild(
3093 PSDevice pDevice,
3094 PKnownBSS pCurr
3097 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
3098 // unsigned int ii , uSameBssidNum=0;
3100 // for (ii = 0; ii < MAX_BSS_NUM; ii++) {
3101 // if (pMgmt->sBSSList[ii].bActive &&
3102 // !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
3103 // uSameBssidNum++;
3104 // }
3105 // }
3106 // if( uSameBssidNum>=2) { //we only check AP in hidden sssid mode
3107 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || //networkmanager 0.7.0 does not give the pairwise-key selsection,
3108 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { // so we need re-selsect it according to real pairwise-key info.
3109 if(pCurr->bWPAValid == true) { //WPA-PSK
3110 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
3111 if(pCurr->abyPKType[0] == WPA_TKIP) {
3112 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
3113 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
3115 else if(pCurr->abyPKType[0] == WPA_AESCCMP) {
3116 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
3117 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
3120 else if(pCurr->bWPA2Valid == true) { //WPA2-PSK
3121 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
3122 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
3123 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
3124 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
3126 else if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
3127 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
3128 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
3132 // }
3133 return;
3139 * Routine Description:
3140 * Format TIM field
3143 * Return Value:
3144 * void
3148 static
3149 void
3150 s_vMgrFormatTIM(
3151 PSMgmtObject pMgmt,
3152 PWLAN_IE_TIM pTIM
3155 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
3156 unsigned char byMap;
3157 unsigned int ii, jj;
3158 bool bStartFound = false;
3159 bool bMulticast = false;
3160 unsigned short wStartIndex = 0;
3161 unsigned short wEndIndex = 0;
3164 // Find size of partial virtual bitmap
3165 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
3166 byMap = pMgmt->abyPSTxMap[ii];
3167 if (!ii) {
3168 // Mask out the broadcast bit which is indicated separately.
3169 bMulticast = (byMap & byMask[0]) != 0;
3170 if(bMulticast) {
3171 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
3173 byMap = 0;
3175 if (byMap) {
3176 if (!bStartFound) {
3177 bStartFound = true;
3178 wStartIndex = ii;
3180 wEndIndex = ii;
3185 // Round start index down to nearest even number
3186 wStartIndex &= ~BIT0;
3188 // Round end index up to nearest even number
3189 wEndIndex = ((wEndIndex + 1) & ~BIT0);
3191 // Size of element payload
3193 pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
3195 // Fill in the Fixed parts of the TIM
3196 pTIM->byDTIMCount = pMgmt->byDTIMCount;
3197 pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
3198 pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
3199 (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
3201 // Append variable part of TIM
3203 for (ii = wStartIndex, jj =0 ; ii <= wEndIndex; ii++, jj++) {
3204 pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
3207 // Aid = 0 don't used.
3208 pTIM->byVirtBitMap[0] &= ~BIT0;
3214 * Routine Description:
3215 * Constructs an Beacon frame( Ad-hoc mode)
3218 * Return Value:
3219 * PTR to frame; or NULL on allocation failue
3223 static
3224 PSTxMgmtPacket
3225 s_MgrMakeBeacon(
3226 PSDevice pDevice,
3227 PSMgmtObject pMgmt,
3228 unsigned short wCurrCapInfo,
3229 unsigned short wCurrBeaconPeriod,
3230 unsigned int uCurrChannel,
3231 unsigned short wCurrATIMWinodw,
3232 PWLAN_IE_SSID pCurrSSID,
3233 unsigned char *pCurrBSSID,
3234 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3235 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3238 PSTxMgmtPacket pTxPacket = NULL;
3239 WLAN_FR_BEACON sFrame;
3240 unsigned char abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3241 unsigned char *pbyBuffer;
3242 unsigned int uLength = 0;
3243 PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
3244 unsigned int ii;
3246 // prepare beacon frame
3247 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3248 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN);
3249 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3250 // Setup the sFrame structure.
3251 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3252 sFrame.len = WLAN_BEACON_FR_MAXLEN;
3253 vMgrEncodeBeacon(&sFrame);
3254 // Setup the header
3255 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3257 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3258 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
3261 if (pDevice->bEnablePSMode) {
3262 sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_PWRMGT(1));
3265 memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
3266 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3267 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3268 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3269 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3270 // Copy SSID
3271 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3272 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3273 memcpy(sFrame.pSSID,
3274 pCurrSSID,
3275 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3277 // Copy the rate set
3278 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3279 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3280 memcpy(sFrame.pSuppRates,
3281 pCurrSuppRates,
3282 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3284 // DS parameter
3285 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
3286 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3287 sFrame.len += (1) + WLAN_IEHDR_LEN;
3288 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3289 sFrame.pDSParms->len = 1;
3290 sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
3292 // TIM field
3293 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
3294 sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
3295 sFrame.pTIM->byElementID = WLAN_EID_TIM;
3296 s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
3297 sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
3300 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3302 // IBSS parameter
3303 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3304 sFrame.len += (2) + WLAN_IEHDR_LEN;
3305 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3306 sFrame.pIBSSParms->len = 2;
3307 sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
3308 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3309 /* RSN parameter */
3310 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3311 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3312 sFrame.pRSNWPA->len = 12;
3313 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3314 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3315 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3316 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3317 sFrame.pRSNWPA->wVersion = 1;
3318 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3319 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3320 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3321 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
3322 sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
3323 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
3324 sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
3325 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
3326 sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
3327 else
3328 sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
3330 // Pairwise Key Cipher Suite
3331 sFrame.pRSNWPA->wPKCount = 0;
3332 // Auth Key Management Suite
3333 *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
3334 sFrame.pRSNWPA->len +=2;
3336 // RSN Capabilites
3337 *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
3338 sFrame.pRSNWPA->len +=2;
3339 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3343 if ((pMgmt->b11hEnable == true) &&
3344 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
3345 // Country IE
3346 pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
3347 set_country_IE(pMgmt->pAdapter, pbyBuffer);
3348 set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
3349 uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
3350 pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
3351 // Power Constrain IE
3352 ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
3353 ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
3354 ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
3355 pbyBuffer += (1) + WLAN_IEHDR_LEN;
3356 uLength += (1) + WLAN_IEHDR_LEN;
3357 if (pMgmt->bSwitchChannel == true) {
3358 // Channel Switch IE
3359 ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
3360 ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
3361 ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
3362 ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
3363 ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
3364 pbyBuffer += (3) + WLAN_IEHDR_LEN;
3365 uLength += (3) + WLAN_IEHDR_LEN;
3367 // TPC report
3368 ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
3369 ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
3370 ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
3371 ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
3372 pbyBuffer += (2) + WLAN_IEHDR_LEN;
3373 uLength += (2) + WLAN_IEHDR_LEN;
3374 // IBSS DFS
3375 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3376 pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
3377 pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
3378 pIBSSDFS->len = 7;
3379 memcpy( pIBSSDFS->abyDFSOwner,
3380 pMgmt->abyIBSSDFSOwner,
3382 pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
3383 pbyBuffer += (7) + WLAN_IEHDR_LEN;
3384 uLength += (7) + WLAN_IEHDR_LEN;
3385 for(ii=CB_MAX_CHANNEL_24G+1; ii<=CB_MAX_CHANNEL; ii++ ) {
3386 if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == true) {
3387 pbyBuffer += 2;
3388 uLength += 2;
3389 pIBSSDFS->len += 2;
3393 sFrame.len += uLength;
3396 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
3397 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3398 sFrame.len += 1 + WLAN_IEHDR_LEN;
3399 sFrame.pERP->byElementID = WLAN_EID_ERP;
3400 sFrame.pERP->len = 1;
3401 sFrame.pERP->byContext = 0;
3402 if (pDevice->bProtectMode == true)
3403 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3404 if (pDevice->bNonERPPresent == true)
3405 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3406 if (pDevice->bBarkerPreambleMd == true)
3407 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3409 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3410 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3411 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3412 memcpy(sFrame.pExtSuppRates,
3413 pCurrExtSuppRates,
3414 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3417 // hostapd wpa/wpa2 IE
3418 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
3419 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3420 if (pMgmt->wWPAIELen != 0) {
3421 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3422 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3423 sFrame.len += pMgmt->wWPAIELen;
3428 /* Adjust the length fields */
3429 pTxPacket->cbMPDULen = sFrame.len;
3430 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3432 return pTxPacket;
3441 * Routine Description:
3442 * Constructs an Prob-response frame
3445 * Return Value:
3446 * PTR to frame; or NULL on allocation failue
3453 PSTxMgmtPacket
3454 s_MgrMakeProbeResponse(
3455 PSDevice pDevice,
3456 PSMgmtObject pMgmt,
3457 unsigned short wCurrCapInfo,
3458 unsigned short wCurrBeaconPeriod,
3459 unsigned int uCurrChannel,
3460 unsigned short wCurrATIMWinodw,
3461 unsigned char *pDstAddr,
3462 PWLAN_IE_SSID pCurrSSID,
3463 unsigned char *pCurrBSSID,
3464 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3465 PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
3466 unsigned char byPHYType
3469 PSTxMgmtPacket pTxPacket = NULL;
3470 WLAN_FR_PROBERESP sFrame;
3471 unsigned char *pbyBuffer;
3472 unsigned int uLength = 0;
3473 PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
3474 unsigned int ii;
3477 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3478 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN);
3479 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3480 // Setup the sFrame structure.
3481 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3482 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
3483 vMgrEncodeProbeResponse(&sFrame);
3484 // Setup the header
3485 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3487 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3488 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
3490 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3491 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3492 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3493 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3494 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3496 if (byPHYType == BB_TYPE_11B) {
3497 *sFrame.pwCapInfo &= cpu_to_le16((unsigned short)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
3500 // Copy SSID
3501 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3502 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3503 memcpy(sFrame.pSSID,
3504 pCurrSSID,
3505 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3507 // Copy the rate set
3508 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3510 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3511 memcpy(sFrame.pSuppRates,
3512 pCurrSuppRates,
3513 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3516 // DS parameter
3517 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
3518 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3519 sFrame.len += (1) + WLAN_IEHDR_LEN;
3520 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3521 sFrame.pDSParms->len = 1;
3522 sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
3525 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3526 // IBSS parameter
3527 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3528 sFrame.len += (2) + WLAN_IEHDR_LEN;
3529 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3530 sFrame.pIBSSParms->len = 2;
3531 sFrame.pIBSSParms->wATIMWindow = 0;
3533 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
3534 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3535 sFrame.len += 1 + WLAN_IEHDR_LEN;
3536 sFrame.pERP->byElementID = WLAN_EID_ERP;
3537 sFrame.pERP->len = 1;
3538 sFrame.pERP->byContext = 0;
3539 if (pDevice->bProtectMode == true)
3540 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3541 if (pDevice->bNonERPPresent == true)
3542 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3543 if (pDevice->bBarkerPreambleMd == true)
3544 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3547 if ((pMgmt->b11hEnable == true) &&
3548 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
3549 // Country IE
3550 pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
3551 set_country_IE(pMgmt->pAdapter, pbyBuffer);
3552 set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
3553 uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
3554 pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
3555 // Power Constrain IE
3556 ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
3557 ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
3558 ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
3559 pbyBuffer += (1) + WLAN_IEHDR_LEN;
3560 uLength += (1) + WLAN_IEHDR_LEN;
3561 if (pMgmt->bSwitchChannel == true) {
3562 // Channel Switch IE
3563 ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
3564 ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
3565 ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
3566 ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
3567 ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
3568 pbyBuffer += (3) + WLAN_IEHDR_LEN;
3569 uLength += (3) + WLAN_IEHDR_LEN;
3571 // TPC report
3572 ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
3573 ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
3574 ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
3575 ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
3576 pbyBuffer += (2) + WLAN_IEHDR_LEN;
3577 uLength += (2) + WLAN_IEHDR_LEN;
3578 // IBSS DFS
3579 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3580 pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
3581 pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
3582 pIBSSDFS->len = 7;
3583 memcpy( pIBSSDFS->abyDFSOwner,
3584 pMgmt->abyIBSSDFSOwner,
3586 pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
3587 pbyBuffer += (7) + WLAN_IEHDR_LEN;
3588 uLength += (7) + WLAN_IEHDR_LEN;
3589 for(ii=CB_MAX_CHANNEL_24G+1; ii<=CB_MAX_CHANNEL; ii++ ) {
3590 if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == true) {
3591 pbyBuffer += 2;
3592 uLength += 2;
3593 pIBSSDFS->len += 2;
3597 sFrame.len += uLength;
3601 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3602 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3603 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3604 memcpy(sFrame.pExtSuppRates,
3605 pCurrExtSuppRates,
3606 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3610 // hostapd wpa/wpa2 IE
3611 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
3612 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3613 if (pMgmt->wWPAIELen != 0) {
3614 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3615 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3616 sFrame.len += pMgmt->wWPAIELen;
3621 // Adjust the length fields
3622 pTxPacket->cbMPDULen = sFrame.len;
3623 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3625 return pTxPacket;
3632 * Routine Description:
3633 * Constructs an association request frame
3636 * Return Value:
3637 * A ptr to frame or NULL on allocation failue
3642 PSTxMgmtPacket
3643 s_MgrMakeAssocRequest(
3644 PSDevice pDevice,
3645 PSMgmtObject pMgmt,
3646 unsigned char *pDAddr,
3647 unsigned short wCurrCapInfo,
3648 unsigned short wListenInterval,
3649 PWLAN_IE_SSID pCurrSSID,
3650 PWLAN_IE_SUPP_RATES pCurrRates,
3651 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3654 PSTxMgmtPacket pTxPacket = NULL;
3655 WLAN_FR_ASSOCREQ sFrame;
3656 unsigned char *pbyIEs;
3657 unsigned char *pbyRSN;
3660 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3661 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
3662 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3663 // Setup the sFrame structure.
3664 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3665 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
3666 // format fixed field frame structure
3667 vMgrEncodeAssocRequest(&sFrame);
3668 // Setup the header
3669 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3671 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3672 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
3674 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3675 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3676 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3678 // Set the capibility and listen interval
3679 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3680 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3682 // sFrame.len point to end of fixed field
3683 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3684 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3685 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3687 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3688 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3689 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3690 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3691 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3693 // Copy the rate set
3694 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3695 if ((pDevice->eCurrentPHYType == PHY_TYPE_11B) && (pCurrRates->len > 4))
3696 sFrame.len += 4 + WLAN_IEHDR_LEN;
3697 else
3698 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3699 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3701 // Copy the extension rate set
3702 if ((pDevice->eCurrentPHYType == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3703 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3704 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3705 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3708 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3709 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3710 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3712 // for 802.11h
3713 if (pMgmt->b11hEnable == true) {
3714 if (sFrame.pCurrPowerCap == NULL) {
3715 sFrame.pCurrPowerCap = (PWLAN_IE_PW_CAP)(sFrame.pBuf + sFrame.len);
3716 sFrame.len += (2 + WLAN_IEHDR_LEN);
3717 sFrame.pCurrPowerCap->byElementID = WLAN_EID_PWR_CAPABILITY;
3718 sFrame.pCurrPowerCap->len = 2;
3719 CARDvGetPowerCapability(pMgmt->pAdapter,
3720 &(sFrame.pCurrPowerCap->byMinPower),
3721 &(sFrame.pCurrPowerCap->byMaxPower)
3724 if (sFrame.pCurrSuppCh == NULL) {
3725 sFrame.pCurrSuppCh = (PWLAN_IE_SUPP_CH)(sFrame.pBuf + sFrame.len);
3726 sFrame.len += set_support_channels(pMgmt->pAdapter,(unsigned char *)sFrame.pCurrSuppCh);
3730 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3731 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3732 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3733 (pMgmt->pCurrBSS != NULL)) {
3734 /* WPA IE */
3735 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3736 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3737 sFrame.pRSNWPA->len = 16;
3738 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3739 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3740 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3741 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3742 sFrame.pRSNWPA->wVersion = 1;
3743 //Group Key Cipher Suite
3744 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3745 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3746 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3747 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3748 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3749 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3750 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3751 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3752 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3753 } else {
3754 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3756 // Pairwise Key Cipher Suite
3757 sFrame.pRSNWPA->wPKCount = 1;
3758 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3759 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3760 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3761 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3762 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3763 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3764 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3765 } else {
3766 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3768 // Auth Key Management Suite
3769 pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
3770 *pbyRSN++=0x01;
3771 *pbyRSN++=0x00;
3772 *pbyRSN++=0x00;
3774 *pbyRSN++=0x50;
3775 *pbyRSN++=0xf2;
3776 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3777 *pbyRSN++=WPA_AUTH_PSK;
3779 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3780 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3782 else {
3783 *pbyRSN++=WPA_NONE;
3786 sFrame.pRSNWPA->len +=6;
3788 // RSN Capabilites
3790 *pbyRSN++=0x00;
3791 *pbyRSN++=0x00;
3792 sFrame.pRSNWPA->len +=2;
3794 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3795 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3796 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3797 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
3798 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3800 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3801 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3802 (pMgmt->pCurrBSS != NULL)) {
3803 unsigned int ii;
3804 unsigned short *pwPMKID;
3806 // WPA IE
3807 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3808 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3809 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3810 sFrame.pRSN->wVersion = 1;
3811 //Group Key Cipher Suite
3812 sFrame.pRSN->abyRSN[0] = 0x00;
3813 sFrame.pRSN->abyRSN[1] = 0x0F;
3814 sFrame.pRSN->abyRSN[2] = 0xAC;
3815 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3816 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3817 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3818 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3819 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3820 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3821 } else {
3822 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3825 // Pairwise Key Cipher Suite
3826 sFrame.pRSN->abyRSN[4] = 1;
3827 sFrame.pRSN->abyRSN[5] = 0;
3828 sFrame.pRSN->abyRSN[6] = 0x00;
3829 sFrame.pRSN->abyRSN[7] = 0x0F;
3830 sFrame.pRSN->abyRSN[8] = 0xAC;
3831 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3832 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3833 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3834 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3835 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3836 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3837 } else {
3838 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3840 sFrame.pRSN->len += 6;
3842 // Auth Key Management Suite
3843 sFrame.pRSN->abyRSN[10] = 1;
3844 sFrame.pRSN->abyRSN[11] = 0;
3845 sFrame.pRSN->abyRSN[12] = 0x00;
3846 sFrame.pRSN->abyRSN[13] = 0x0F;
3847 sFrame.pRSN->abyRSN[14] = 0xAC;
3848 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3849 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3850 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3851 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3852 } else {
3853 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3855 sFrame.pRSN->len +=6;
3857 // RSN Capabilites
3858 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3859 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3860 } else {
3861 sFrame.pRSN->abyRSN[16] = 0;
3862 sFrame.pRSN->abyRSN[17] = 0;
3864 sFrame.pRSN->len +=2;
3866 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3867 // RSN PMKID
3868 pbyRSN = &sFrame.pRSN->abyRSN[18];
3869 pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
3870 *pwPMKID = 0; // Initialize PMKID count
3871 pbyRSN += 2; // Point to PMKID list
3872 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3873 if ( !memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
3874 (*pwPMKID) ++;
3875 memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
3876 pbyRSN += 16;
3879 if (*pwPMKID != 0) {
3880 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3884 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3885 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3886 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3887 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
3888 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3892 // Adjust the length fields
3893 pTxPacket->cbMPDULen = sFrame.len;
3894 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3895 return pTxPacket;
3907 * Routine Description:
3908 * Constructs an re-association request frame
3911 * Return Value:
3912 * A ptr to frame or NULL on allocation failue
3917 PSTxMgmtPacket
3918 s_MgrMakeReAssocRequest(
3919 PSDevice pDevice,
3920 PSMgmtObject pMgmt,
3921 unsigned char *pDAddr,
3922 unsigned short wCurrCapInfo,
3923 unsigned short wListenInterval,
3924 PWLAN_IE_SSID pCurrSSID,
3925 PWLAN_IE_SUPP_RATES pCurrRates,
3926 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3929 PSTxMgmtPacket pTxPacket = NULL;
3930 WLAN_FR_REASSOCREQ sFrame;
3931 unsigned char *pbyIEs;
3932 unsigned char *pbyRSN;
3935 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3936 memset( pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN);
3937 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3938 /* Setup the sFrame structure. */
3939 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3940 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
3942 // format fixed field frame structure
3943 vMgrEncodeReassocRequest(&sFrame);
3945 /* Setup the header */
3946 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3948 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3949 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
3951 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3952 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3953 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3955 /* Set the capibility and listen interval */
3956 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3957 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3959 memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3960 /* Copy the SSID */
3961 /* sFrame.len point to end of fixed field */
3962 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3963 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3964 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3966 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3967 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3968 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3969 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3970 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3972 /* Copy the rate set */
3973 /* sFrame.len point to end of SSID */
3974 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3975 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3976 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3978 // Copy the extension rate set
3979 if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3980 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3981 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3982 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3985 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3986 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3987 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3989 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3990 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3991 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3992 (pMgmt->pCurrBSS != NULL)) {
3993 /* WPA IE */
3994 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3995 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3996 sFrame.pRSNWPA->len = 16;
3997 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3998 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3999 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
4000 sFrame.pRSNWPA->abyOUI[3] = 0x01;
4001 sFrame.pRSNWPA->wVersion = 1;
4002 //Group Key Cipher Suite
4003 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
4004 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
4005 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
4006 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
4007 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
4008 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
4009 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
4010 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
4011 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
4012 } else {
4013 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
4015 // Pairwise Key Cipher Suite
4016 sFrame.pRSNWPA->wPKCount = 1;
4017 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
4018 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
4019 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
4020 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
4021 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
4022 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
4023 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
4024 } else {
4025 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
4027 // Auth Key Management Suite
4028 pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
4029 *pbyRSN++=0x01;
4030 *pbyRSN++=0x00;
4031 *pbyRSN++=0x00;
4033 *pbyRSN++=0x50;
4034 *pbyRSN++=0xf2;
4035 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
4036 *pbyRSN++=WPA_AUTH_PSK;
4037 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
4038 *pbyRSN++=WPA_AUTH_IEEE802_1X;
4039 } else {
4040 *pbyRSN++=WPA_NONE;
4043 sFrame.pRSNWPA->len +=6;
4045 // RSN Capabilites
4046 *pbyRSN++=0x00;
4047 *pbyRSN++=0x00;
4048 sFrame.pRSNWPA->len +=2;
4050 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
4051 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
4052 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
4053 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
4054 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
4056 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
4057 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
4058 (pMgmt->pCurrBSS != NULL)) {
4059 unsigned int ii;
4060 unsigned short *pwPMKID;
4062 /* WPA IE */
4063 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
4064 sFrame.pRSN->byElementID = WLAN_EID_RSN;
4065 sFrame.pRSN->len = 6; //Version(2)+GK(4)
4066 sFrame.pRSN->wVersion = 1;
4067 //Group Key Cipher Suite
4068 sFrame.pRSN->abyRSN[0] = 0x00;
4069 sFrame.pRSN->abyRSN[1] = 0x0F;
4070 sFrame.pRSN->abyRSN[2] = 0xAC;
4071 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
4072 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
4073 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
4074 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
4075 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
4076 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
4077 } else {
4078 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
4081 // Pairwise Key Cipher Suite
4082 sFrame.pRSN->abyRSN[4] = 1;
4083 sFrame.pRSN->abyRSN[5] = 0;
4084 sFrame.pRSN->abyRSN[6] = 0x00;
4085 sFrame.pRSN->abyRSN[7] = 0x0F;
4086 sFrame.pRSN->abyRSN[8] = 0xAC;
4087 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
4088 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
4089 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
4090 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
4091 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
4092 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
4093 } else {
4094 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
4096 sFrame.pRSN->len += 6;
4098 // Auth Key Management Suite
4099 sFrame.pRSN->abyRSN[10] = 1;
4100 sFrame.pRSN->abyRSN[11] = 0;
4101 sFrame.pRSN->abyRSN[12] = 0x00;
4102 sFrame.pRSN->abyRSN[13] = 0x0F;
4103 sFrame.pRSN->abyRSN[14] = 0xAC;
4104 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
4105 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
4106 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
4107 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
4108 } else {
4109 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
4111 sFrame.pRSN->len +=6;
4113 // RSN Capabilites
4114 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
4115 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
4116 } else {
4117 sFrame.pRSN->abyRSN[16] = 0;
4118 sFrame.pRSN->abyRSN[17] = 0;
4120 sFrame.pRSN->len +=2;
4122 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
4123 // RSN PMKID
4124 pbyRSN = &sFrame.pRSN->abyRSN[18];
4125 pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
4126 *pwPMKID = 0; // Initialize PMKID count
4127 pbyRSN += 2; // Point to PMKID list
4128 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
4129 if ( !memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
4130 (*pwPMKID) ++;
4131 memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
4132 pbyRSN += 16;
4135 if (*pwPMKID != 0) {
4136 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
4140 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
4141 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
4142 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
4143 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
4144 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
4148 /* Adjust the length fields */
4149 pTxPacket->cbMPDULen = sFrame.len;
4150 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
4152 return pTxPacket;
4159 * Routine Description:
4160 * Constructs an assoc-response frame
4163 * Return Value:
4164 * PTR to frame; or NULL on allocation failue
4169 PSTxMgmtPacket
4170 s_MgrMakeAssocResponse(
4171 PSDevice pDevice,
4172 PSMgmtObject pMgmt,
4173 unsigned short wCurrCapInfo,
4174 unsigned short wAssocStatus,
4175 unsigned short wAssocAID,
4176 unsigned char *pDstAddr,
4177 PWLAN_IE_SUPP_RATES pCurrSuppRates,
4178 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
4181 PSTxMgmtPacket pTxPacket = NULL;
4182 WLAN_FR_ASSOCRESP sFrame;
4185 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
4186 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
4187 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
4188 // Setup the sFrame structure
4189 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
4190 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
4191 vMgrEncodeAssocResponse(&sFrame);
4192 // Setup the header
4193 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
4195 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
4196 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
4198 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
4199 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
4200 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
4202 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
4203 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
4204 *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
4206 // Copy the rate set
4207 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4208 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
4209 memcpy(sFrame.pSuppRates,
4210 pCurrSuppRates,
4211 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
4214 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
4215 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4216 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
4217 memcpy(sFrame.pExtSuppRates,
4218 pCurrExtSuppRates,
4219 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
4223 // Adjust the length fields
4224 pTxPacket->cbMPDULen = sFrame.len;
4225 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
4227 return pTxPacket;
4233 * Routine Description:
4234 * Constructs an reassoc-response frame
4237 * Return Value:
4238 * PTR to frame; or NULL on allocation failue
4243 PSTxMgmtPacket
4244 s_MgrMakeReAssocResponse(
4245 PSDevice pDevice,
4246 PSMgmtObject pMgmt,
4247 unsigned short wCurrCapInfo,
4248 unsigned short wAssocStatus,
4249 unsigned short wAssocAID,
4250 unsigned char *pDstAddr,
4251 PWLAN_IE_SUPP_RATES pCurrSuppRates,
4252 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
4255 PSTxMgmtPacket pTxPacket = NULL;
4256 WLAN_FR_REASSOCRESP sFrame;
4259 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
4260 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
4261 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
4262 // Setup the sFrame structure
4263 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
4264 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
4265 vMgrEncodeReassocResponse(&sFrame);
4266 // Setup the header
4267 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
4269 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
4270 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
4272 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
4273 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
4274 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
4276 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
4277 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
4278 *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
4280 // Copy the rate set
4281 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4282 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
4283 memcpy(sFrame.pSuppRates,
4284 pCurrSuppRates,
4285 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
4288 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
4289 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4290 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
4291 memcpy(sFrame.pExtSuppRates,
4292 pCurrExtSuppRates,
4293 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
4297 // Adjust the length fields
4298 pTxPacket->cbMPDULen = sFrame.len;
4299 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
4301 return pTxPacket;
4307 * Routine Description:
4308 * Handles probe response management frames.
4311 * Return Value:
4312 * none.
4316 static
4317 void
4318 s_vMgrRxProbeResponse(
4319 PSDevice pDevice,
4320 PSMgmtObject pMgmt,
4321 PSRxMgmtPacket pRxPacket
4324 PKnownBSS pBSSList = NULL;
4325 WLAN_FR_PROBERESP sFrame;
4326 unsigned char byCurrChannel = pRxPacket->byRxChannel;
4327 ERPObject sERP;
4328 unsigned char byIEChannel = 0;
4329 bool bChannelHit = true;
4332 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
4333 // decode the frame
4334 sFrame.len = pRxPacket->cbMPDULen;
4335 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
4336 vMgrDecodeProbeResponse(&sFrame);
4338 if ((sFrame.pqwTimestamp == 0) ||
4339 (sFrame.pwBeaconInterval == 0) ||
4340 (sFrame.pwCapInfo == 0) ||
4341 (sFrame.pSSID == 0) ||
4342 (sFrame.pSuppRates == 0)) {
4343 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p] \n", pRxPacket->p80211Header);
4344 DBG_PORT80(0xCC);
4345 return;
4348 if(sFrame.pSSID->len == 0)
4349 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
4351 if (sFrame.pDSParms != 0) {
4352 if (byCurrChannel > CB_MAX_CHANNEL_24G) {
4353 // channel remapping to
4354 byIEChannel = get_channel_mapping(pMgmt->pAdapter, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
4355 } else {
4356 byIEChannel = sFrame.pDSParms->byCurrChannel;
4358 if (byCurrChannel != byIEChannel) {
4359 // adjust channel info. bcs we rcv adjcent channel pakckets
4360 bChannelHit = false;
4361 byCurrChannel = byIEChannel;
4363 } else {
4364 // no DS channel info
4365 bChannelHit = true;
4368 //2008-0730-01<Add>by MikeLiu
4369 if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
4370 return;
4372 if (sFrame.pERP != NULL) {
4373 sERP.byERP = sFrame.pERP->byContext;
4374 sERP.bERPExist = true;
4375 } else {
4376 sERP.bERPExist = false;
4377 sERP.byERP = 0;
4381 // update or insert the bss
4382 pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
4383 if (pBSSList) {
4384 BSSbUpdateToBSSList((void *)pDevice,
4385 *sFrame.pqwTimestamp,
4386 *sFrame.pwBeaconInterval,
4387 *sFrame.pwCapInfo,
4388 byCurrChannel,
4389 bChannelHit,
4390 sFrame.pSSID,
4391 sFrame.pSuppRates,
4392 sFrame.pExtSuppRates,
4393 &sERP,
4394 sFrame.pRSN,
4395 sFrame.pRSNWPA,
4396 sFrame.pIE_Country,
4397 sFrame.pIE_Quiet,
4398 pBSSList,
4399 sFrame.len - WLAN_HDR_ADDR3_LEN,
4400 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
4401 (void *)pRxPacket
4404 else {
4405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
4406 BSSbInsertToBSSList((void *)pDevice,
4407 sFrame.pHdr->sA3.abyAddr3,
4408 *sFrame.pqwTimestamp,
4409 *sFrame.pwBeaconInterval,
4410 *sFrame.pwCapInfo,
4411 byCurrChannel,
4412 sFrame.pSSID,
4413 sFrame.pSuppRates,
4414 sFrame.pExtSuppRates,
4415 &sERP,
4416 sFrame.pRSN,
4417 sFrame.pRSNWPA,
4418 sFrame.pIE_Country,
4419 sFrame.pIE_Quiet,
4420 sFrame.len - WLAN_HDR_ADDR3_LEN,
4421 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
4422 (void *)pRxPacket
4425 return;
4431 * Routine Description:(AP)or(Ad-hoc STA)
4432 * Handles probe request management frames.
4435 * Return Value:
4436 * none.
4441 static
4442 void
4443 s_vMgrRxProbeRequest(
4444 PSDevice pDevice,
4445 PSMgmtObject pMgmt,
4446 PSRxMgmtPacket pRxPacket
4449 WLAN_FR_PROBEREQ sFrame;
4450 CMD_STATUS Status;
4451 PSTxMgmtPacket pTxPacket;
4452 unsigned char byPHYType = BB_TYPE_11B;
4454 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
4455 // STA have to response this request.
4456 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
4457 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
4459 memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
4460 // decode the frame
4461 sFrame.len = pRxPacket->cbMPDULen;
4462 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
4463 vMgrDecodeProbeRequest(&sFrame);
4465 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%02x-%02x-%02x=%02x-%02x-%02x \n",
4466 sFrame.pHdr->sA3.abyAddr2[0],
4467 sFrame.pHdr->sA3.abyAddr2[1],
4468 sFrame.pHdr->sA3.abyAddr2[2],
4469 sFrame.pHdr->sA3.abyAddr2[3],
4470 sFrame.pHdr->sA3.abyAddr2[4],
4471 sFrame.pHdr->sA3.abyAddr2[5]
4474 if (sFrame.pSSID->len != 0) {
4475 if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
4476 return;
4477 if (memcmp(sFrame.pSSID->abySSID,
4478 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
4479 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
4480 return;
4484 if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
4485 byPHYType = BB_TYPE_11G;
4488 // Probe response reply..
4489 pTxPacket = s_MgrMakeProbeResponse
4491 pDevice,
4492 pMgmt,
4493 pMgmt->wCurrCapInfo,
4494 pMgmt->wCurrBeaconPeriod,
4495 pMgmt->uCurrChannel,
4497 sFrame.pHdr->sA3.abyAddr2,
4498 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4499 (unsigned char *)pMgmt->abyCurrBSSID,
4500 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4501 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
4502 byPHYType
4504 if (pTxPacket != NULL ){
4505 /* send the frame */
4506 Status = csMgmt_xmit(pDevice, pTxPacket);
4507 if (Status != CMD_STATUS_PENDING) {
4508 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
4510 else {
4511 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
4516 return;
4525 * Routine Description:
4527 * Entry point for the reception and handling of 802.11 management
4528 * frames. Makes a determination of the frame type and then calls
4529 * the appropriate function.
4532 * Return Value:
4533 * none.
4538 void
4539 vMgrRxManagePacket(
4540 void *hDeviceContext,
4541 PSMgmtObject pMgmt,
4542 PSRxMgmtPacket pRxPacket
4545 PSDevice pDevice = (PSDevice)hDeviceContext;
4546 bool bInScan = false;
4547 unsigned int uNodeIndex = 0;
4548 NODE_STATE eNodeState = 0;
4549 CMD_STATUS Status;
4552 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
4553 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
4554 eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
4557 switch( WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) ){
4559 case WLAN_FSTYPE_ASSOCREQ:
4560 // Frame Clase = 2
4561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
4562 if (eNodeState < NODE_AUTH) {
4563 // send deauth notification
4564 // reason = (6) class 2 received from nonauth sta
4565 vMgrDeAuthenBeginSta(pDevice,
4566 pMgmt,
4567 pRxPacket->p80211Header->sA3.abyAddr2,
4568 (6),
4569 &Status
4571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
4573 else {
4574 s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
4576 break;
4578 case WLAN_FSTYPE_ASSOCRESP:
4579 // Frame Clase = 2
4580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
4581 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
4582 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
4583 break;
4585 case WLAN_FSTYPE_REASSOCREQ:
4586 // Frame Clase = 2
4587 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
4588 // Todo: reassoc
4589 if (eNodeState < NODE_AUTH) {
4590 // send deauth notification
4591 // reason = (6) class 2 received from nonauth sta
4592 vMgrDeAuthenBeginSta(pDevice,
4593 pMgmt,
4594 pRxPacket->p80211Header->sA3.abyAddr2,
4595 (6),
4596 &Status
4598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
4601 s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
4602 break;
4604 case WLAN_FSTYPE_REASSOCRESP:
4605 // Frame Clase = 2
4606 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
4607 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
4608 break;
4610 case WLAN_FSTYPE_PROBEREQ:
4611 // Frame Clase = 0
4612 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
4613 s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
4614 break;
4616 case WLAN_FSTYPE_PROBERESP:
4617 // Frame Clase = 0
4618 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
4620 s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
4621 break;
4623 case WLAN_FSTYPE_BEACON:
4624 // Frame Clase = 0
4625 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
4626 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
4627 bInScan = true;
4629 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4630 break;
4632 case WLAN_FSTYPE_ATIM:
4633 // Frame Clase = 1
4634 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
4635 break;
4637 case WLAN_FSTYPE_DISASSOC:
4638 // Frame Clase = 2
4639 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
4640 if (eNodeState < NODE_AUTH) {
4641 // send deauth notification
4642 // reason = (6) class 2 received from nonauth sta
4643 vMgrDeAuthenBeginSta(pDevice,
4644 pMgmt,
4645 pRxPacket->p80211Header->sA3.abyAddr2,
4646 (6),
4647 &Status
4649 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
4651 s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
4652 break;
4654 case WLAN_FSTYPE_AUTHEN:
4655 // Frame Clase = 1
4656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx authen\n");
4657 s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
4658 break;
4660 case WLAN_FSTYPE_DEAUTHEN:
4661 // Frame Clase = 1
4662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
4663 s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
4664 break;
4666 default:
4667 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
4670 return;
4678 * Routine Description:
4681 * Prepare beacon to send
4683 * Return Value:
4684 * true if success; false if failed.
4687 bool
4688 bMgrPrepareBeaconToSend(
4689 void *hDeviceContext,
4690 PSMgmtObject pMgmt
4693 PSDevice pDevice = (PSDevice)hDeviceContext;
4694 PSTxMgmtPacket pTxPacket;
4696 // pDevice->bBeaconBufReady = false;
4697 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
4698 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4700 else {
4701 pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
4703 pTxPacket = s_MgrMakeBeacon
4705 pDevice,
4706 pMgmt,
4707 pMgmt->wCurrCapInfo,
4708 pMgmt->wCurrBeaconPeriod,
4709 pMgmt->uCurrChannel,
4710 pMgmt->wCurrATIMWindow, //0,
4711 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4712 (unsigned char *)pMgmt->abyCurrBSSID,
4713 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4714 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
4717 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4718 (pMgmt->abyCurrBSSID[0] == 0))
4719 return false;
4721 csBeacon_xmit(pDevice, pTxPacket);
4723 return true;
4731 * Routine Description:
4733 * Log a warning message based on the contents of the Status
4734 * Code field of an 802.11 management frame. Defines are
4735 * derived from 802.11-1997 SPEC.
4737 * Return Value:
4738 * none.
4741 static
4742 void
4743 s_vMgrLogStatus(
4744 PSMgmtObject pMgmt,
4745 unsigned short wStatus
4748 switch( wStatus ){
4749 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
4750 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
4751 break;
4752 case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
4753 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
4754 break;
4755 case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
4756 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
4757 break;
4758 case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
4759 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
4760 break;
4761 case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
4762 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
4763 break;
4764 case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
4765 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
4766 break;
4767 case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
4768 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge failure.\n");
4769 break;
4770 case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
4771 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
4772 break;
4773 case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
4774 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
4775 break;
4776 case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
4777 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
4778 break;
4779 case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
4780 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
4781 break;
4782 case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
4783 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
4784 break;
4785 case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
4786 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
4787 break;
4788 default:
4789 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
4790 break;
4797 * Description:
4798 * Add BSSID in PMKID Candidate list.
4800 * Parameters:
4801 * In:
4802 * hDeviceContext - device structure point
4803 * pbyBSSID - BSSID address for adding
4804 * wRSNCap - BSS's RSN capability
4805 * Out:
4806 * none
4808 * Return Value: none.
4811 bool
4812 bAdd_PMKID_Candidate (
4813 void *hDeviceContext,
4814 unsigned char *pbyBSSID,
4815 PSRSNCapObject psRSNCapObj
4818 PSDevice pDevice = (PSDevice)hDeviceContext;
4819 PPMKID_CANDIDATE pCandidateList;
4820 unsigned int ii = 0;
4822 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4824 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
4825 return false;
4827 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
4828 return false;
4832 // Update Old Candidate
4833 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
4834 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4835 if ( !memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
4836 if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
4837 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4838 } else {
4839 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4841 return true;
4845 // New Candidate
4846 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
4847 if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
4848 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4849 } else {
4850 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4852 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
4853 pDevice->gsPMKIDCandidate.NumCandidates++;
4854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4855 return true;
4860 * Description:
4861 * Flush PMKID Candidate list.
4863 * Parameters:
4864 * In:
4865 * hDeviceContext - device structure point
4866 * Out:
4867 * none
4869 * Return Value: none.
4872 void
4873 vFlush_PMKID_Candidate (
4874 void *hDeviceContext
4877 PSDevice pDevice = (PSDevice)hDeviceContext;
4879 if (pDevice == NULL)
4880 return;
4882 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
4885 static bool
4886 s_bCipherMatch (
4887 PKnownBSS pBSSNode,
4888 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
4889 unsigned char *pbyCCSPK,
4890 unsigned char *pbyCCSGK
4893 unsigned char byMulticastCipher = KEY_CTL_INVALID;
4894 unsigned char byCipherMask = 0x00;
4895 int i;
4897 if (pBSSNode == NULL)
4898 return false;
4900 // check cap. of BSS
4901 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4902 (EncStatus == Ndis802_11Encryption1Enabled)) {
4903 // default is WEP only
4904 byMulticastCipher = KEY_CTL_WEP;
4907 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4908 (pBSSNode->bWPA2Valid == true) &&
4909 //20080123-01,<Add> by Einsn Liu
4910 ((EncStatus == Ndis802_11Encryption3Enabled)||(EncStatus == Ndis802_11Encryption2Enabled))) {
4911 //WPA2
4912 // check Group Key Cipher
4913 if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
4914 (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
4915 byMulticastCipher = KEY_CTL_WEP;
4916 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
4917 byMulticastCipher = KEY_CTL_TKIP;
4918 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
4919 byMulticastCipher = KEY_CTL_CCMP;
4920 } else {
4921 byMulticastCipher = KEY_CTL_INVALID;
4924 // check Pairwise Key Cipher
4925 for(i=0;i<pBSSNode->wCSSPKCount;i++) {
4926 if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
4927 (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
4928 // this should not happen as defined 802.11i
4929 byCipherMask |= 0x01;
4930 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
4931 byCipherMask |= 0x02;
4932 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
4933 byCipherMask |= 0x04;
4934 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
4935 // use group key only ignore all others
4936 byCipherMask = 0;
4937 i = pBSSNode->wCSSPKCount;
4941 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4942 (pBSSNode->bWPAValid == true) &&
4943 ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
4944 //WPA
4945 // check Group Key Cipher
4946 if ((pBSSNode->byGKType == WPA_WEP40) ||
4947 (pBSSNode->byGKType == WPA_WEP104)) {
4948 byMulticastCipher = KEY_CTL_WEP;
4949 } else if (pBSSNode->byGKType == WPA_TKIP) {
4950 byMulticastCipher = KEY_CTL_TKIP;
4951 } else if (pBSSNode->byGKType == WPA_AESCCMP) {
4952 byMulticastCipher = KEY_CTL_CCMP;
4953 } else {
4954 byMulticastCipher = KEY_CTL_INVALID;
4957 // check Pairwise Key Cipher
4958 for(i=0;i<pBSSNode->wPKCount;i++) {
4959 if (pBSSNode->abyPKType[i] == WPA_TKIP) {
4960 byCipherMask |= 0x02;
4961 } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
4962 byCipherMask |= 0x04;
4963 } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
4964 // use group key only ignore all others
4965 byCipherMask = 0;
4966 i = pBSSNode->wPKCount;
4971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%d, %d, %d, %d, EncStatus:%d\n",
4972 byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
4974 // mask our cap. with BSS
4975 if (EncStatus == Ndis802_11Encryption1Enabled) {
4977 // For supporting Cisco migration mode, don't care pairwise key cipher
4978 if ((byMulticastCipher == KEY_CTL_WEP) &&
4979 (byCipherMask == 0)) {
4980 *pbyCCSGK = KEY_CTL_WEP;
4981 *pbyCCSPK = KEY_CTL_NONE;
4982 return true;
4983 } else {
4984 return false;
4987 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
4988 if ((byMulticastCipher == KEY_CTL_TKIP) &&
4989 (byCipherMask == 0)) {
4990 *pbyCCSGK = KEY_CTL_TKIP;
4991 *pbyCCSPK = KEY_CTL_NONE;
4992 return true;
4993 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4994 ((byCipherMask & 0x02) != 0)) {
4995 *pbyCCSGK = KEY_CTL_WEP;
4996 *pbyCCSPK = KEY_CTL_TKIP;
4997 return true;
4998 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4999 ((byCipherMask & 0x02) != 0)) {
5000 *pbyCCSGK = KEY_CTL_TKIP;
5001 *pbyCCSPK = KEY_CTL_TKIP;
5002 return true;
5003 } else {
5004 return false;
5006 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
5007 if ((byMulticastCipher == KEY_CTL_CCMP) &&
5008 (byCipherMask == 0)) {
5009 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
5010 return false;
5011 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
5012 ((byCipherMask & 0x04) != 0)) {
5013 *pbyCCSGK = KEY_CTL_WEP;
5014 *pbyCCSPK = KEY_CTL_CCMP;
5015 return true;
5016 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
5017 ((byCipherMask & 0x04) != 0)) {
5018 *pbyCCSGK = KEY_CTL_TKIP;
5019 *pbyCCSPK = KEY_CTL_CCMP;
5020 return true;
5021 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
5022 ((byCipherMask & 0x04) != 0)) {
5023 *pbyCCSGK = KEY_CTL_CCMP;
5024 *pbyCCSPK = KEY_CTL_CCMP;
5025 return true;
5026 } else {
5027 return false;
5030 return true;