2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
22 * Purpose: Handles the 802.11 management functions
29 * nsMgrObjectInitial - Initialize Management Objet data structure
30 * vMgrObjectReset - Reset Management Object 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- Assembler TIM field of beacon
58 * vMgrTimerInit- Initial 1-sec and command call back funtions
84 static int msglevel =MSG_LEVEL_INFO;
85 //static int msglevel =MSG_LEVEL_DEBUG;
87 static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel);
89 /* Association/diassociation functions */
90 static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *,
91 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
92 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
93 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
95 static void s_vMgrRxAssocRequest(struct vnt_private *,
96 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
99 static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *,
100 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
101 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
102 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
104 static void s_vMgrRxAssocResponse(struct vnt_private *,
105 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
108 static void s_vMgrRxDisassociation(struct vnt_private *,
109 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
111 /* Authentication/deauthen functions */
112 static void s_vMgrRxAuthenSequence_1(struct vnt_private *,
113 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
115 static void s_vMgrRxAuthenSequence_2(struct vnt_private *,
116 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
118 static void s_vMgrRxAuthenSequence_3(struct vnt_private *,
119 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
121 static void s_vMgrRxAuthenSequence_4(struct vnt_private *,
122 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
124 static void s_vMgrRxAuthentication(struct vnt_private *,
125 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
127 static void s_vMgrRxDeauthentication(struct vnt_private *,
128 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
131 * probe request/response functions */
133 static void s_vMgrRxProbeRequest(struct vnt_private *,
134 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
136 static void s_vMgrRxProbeResponse(struct vnt_private *,
137 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
139 /* beacon functions */
140 static void s_vMgrRxBeacon(struct vnt_private *pDevice,
141 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
144 static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM);
146 static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
147 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
148 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
149 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
150 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
152 /* Association response */
153 static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *,
154 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
155 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
156 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
158 /* ReAssociation response */
159 static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *,
160 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
161 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
162 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
165 static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *,
166 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
167 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
168 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
169 PWLAN_IE_SUPP_RATES pCurrSuppRates,
170 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType);
172 /* received status */
173 static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus);
175 static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode,
176 PKnownBSS pCurr, PCMD_STATUS pStatus);
181 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
186 static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr);
190 * Routine Description:
191 * Allocates and initializes the Management object.
198 void vMgrObjectInit(struct vnt_private *pDevice)
200 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
203 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
204 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
205 pMgmt->uCurrChannel = pDevice->uChannel;
206 for (ii = 0; ii < WLAN_BSSID_LEN; ii++)
207 pMgmt->abyDesireBSSID[ii] = 0xFF;
209 pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
210 //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
211 pMgmt->byCSSPK = KEY_CTL_NONE;
212 pMgmt->byCSSGK = KEY_CTL_NONE;
213 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
214 BSSvClearBSSList((void *) pDevice, false);
216 init_timer(&pMgmt->sTimerSecondCallback);
217 pMgmt->sTimerSecondCallback.data = (unsigned long)pDevice;
218 pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
219 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
221 init_timer(&pDevice->sTimerCommand);
222 pDevice->sTimerCommand.data = (unsigned long)pDevice;
223 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
224 pDevice->sTimerCommand.expires = RUN_AT(HZ);
226 init_timer(&pDevice->sTimerTxData);
227 pDevice->sTimerTxData.data = (unsigned long)pDevice;
228 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
229 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
230 pDevice->fTxDataInSleep = false;
231 pDevice->IsTxDataTrigger = false;
232 pDevice->nTxDataTimeCout = 0;
234 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
235 pDevice->uCmdDequeueIdx = 0;
236 pDevice->uCmdEnqueueIdx = 0;
237 pDevice->eCommandState = WLAN_CMD_IDLE;
238 pDevice->bCmdRunning = false;
239 pDevice->bCmdClear = false;
246 * Routine Description:
247 * Start the station association procedure. Namely, send an
248 * association request frame to the AP.
255 void vMgrAssocBeginSta(struct vnt_private *pDevice,
256 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
258 struct vnt_tx_mgmt *pTxPacket;
260 pMgmt->wCurrCapInfo = 0;
261 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
262 if (pDevice->bEncryptionEnable) {
263 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
265 // always allow receive short preamble
266 //if (pDevice->byPreambleType == 1) {
267 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
269 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
270 if (pMgmt->wListenInterval == 0)
271 pMgmt->wListenInterval = 1; // at least one.
273 // ERP Phy (802.11g) should support short preamble.
274 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
275 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
276 if (pDevice->bShortSlotTime == true)
277 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
279 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
280 if (pDevice->byPreambleType == 1) {
281 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
284 if (pMgmt->b11hEnable == true)
285 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
287 // build an assocreq frame and send it
288 pTxPacket = s_MgrMakeAssocRequest
294 pMgmt->wListenInterval,
295 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
296 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
297 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
300 if (pTxPacket != NULL ){
302 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
303 if (*pStatus == CMD_STATUS_PENDING) {
304 pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
305 *pStatus = CMD_STATUS_SUCCESS;
309 *pStatus = CMD_STATUS_RESOURCES;
316 * Routine Description:
317 * Start the station re-association procedure.
324 void vMgrReAssocBeginSta(struct vnt_private *pDevice,
325 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
327 struct vnt_tx_mgmt *pTxPacket;
329 pMgmt->wCurrCapInfo = 0;
330 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
331 if (pDevice->bEncryptionEnable) {
332 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
335 //if (pDevice->byPreambleType == 1) {
336 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
338 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
340 if (pMgmt->wListenInterval == 0)
341 pMgmt->wListenInterval = 1; // at least one.
343 // ERP Phy (802.11g) should support short preamble.
344 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
345 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
346 if (pDevice->bShortSlotTime == true)
347 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
349 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
350 if (pDevice->byPreambleType == 1) {
351 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
354 if (pMgmt->b11hEnable == true)
355 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
357 pTxPacket = s_MgrMakeReAssocRequest
363 pMgmt->wListenInterval,
364 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
365 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
366 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
369 if (pTxPacket != NULL ){
371 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
372 if (*pStatus != CMD_STATUS_PENDING) {
373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
385 * Routine Description:
386 * Send an dis-association request frame to the AP.
393 void vMgrDisassocBeginSta(struct vnt_private *pDevice,
394 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
397 struct vnt_tx_mgmt *pTxPacket = NULL;
398 WLAN_FR_DISASSOC sFrame;
400 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
401 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
402 + WLAN_DISASSOC_FR_MAXLEN);
403 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
404 + sizeof(struct vnt_tx_mgmt));
406 // Setup the sFrame structure
407 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
408 sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
410 // format fixed field frame structure
411 vMgrEncodeDisassociation(&sFrame);
414 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
416 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
417 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
420 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
421 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
422 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
425 *(sFrame.pwReason) = cpu_to_le16(wReason);
426 pTxPacket->cbMPDULen = sFrame.len;
427 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
430 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
431 if (*pStatus == CMD_STATUS_PENDING) {
432 pMgmt->eCurrState = WMAC_STATE_IDLE;
433 *pStatus = CMD_STATUS_SUCCESS;
441 * Routine Description:(AP function)
442 * Handle incoming station association request frames.
449 static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
450 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
453 WLAN_FR_ASSOCREQ sFrame;
455 struct vnt_tx_mgmt *pTxPacket;
456 u16 wAssocStatus = 0;
458 u32 uRateLen = WLAN_RATES_MAXLEN;
459 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
460 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
462 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
464 // node index not found
468 //check if node is authenticated
470 memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
471 memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
472 memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
473 sFrame.len = pRxPacket->cbMPDULen;
474 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
476 vMgrDecodeAssocRequest(&sFrame);
478 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
479 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
480 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
481 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
482 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
483 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
484 // Todo: check sta basic rate, if ap can't support, set status code
485 if (pDevice->byBBType == BB_TYPE_11B) {
486 uRateLen = WLAN_RATES_MAXLEN_11B;
488 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
489 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
490 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
492 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
493 if (pDevice->byBBType == BB_TYPE_11G) {
494 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
495 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
498 abyCurrExtSuppRates[1] = 0;
501 RATEvParseMaxRate((void *)pDevice,
502 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
503 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
504 false, // do not change our basic rate
505 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
506 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
507 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
508 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
509 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
513 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
514 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
515 // Todo: check sta preamble, if ap can't support, set status code
516 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
517 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
518 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
519 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
520 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
521 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
522 wAssocAID = (u16)uNodeIndex;
523 // check if ERP support
524 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
525 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
527 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
529 pDevice->bProtectMode = true;
530 pDevice->bNonERPPresent = true;
532 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
533 pDevice->bBarkerPreambleMd = true;
536 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
537 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
538 sFrame.pHdr->sA3.abyAddr2[0],
539 sFrame.pHdr->sA3.abyAddr2[1],
540 sFrame.pHdr->sA3.abyAddr2[2],
541 sFrame.pHdr->sA3.abyAddr2[3],
542 sFrame.pHdr->sA3.abyAddr2[4],
543 sFrame.pHdr->sA3.abyAddr2[5]
545 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
546 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
549 // assoc response reply..
550 pTxPacket = s_MgrMakeAssocResponse
557 sFrame.pHdr->sA3.abyAddr2,
558 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
559 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
561 if (pTxPacket != NULL ){
563 if (pDevice->bEnableHostapd) {
567 Status = csMgmt_xmit(pDevice, pTxPacket);
568 if (Status != CMD_STATUS_PENDING) {
569 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
572 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
582 * Description:(AP function)
583 * Handle incoming station re-association request frames.
587 * pMgmt - Management Object structure
588 * pRxPacket - Received Packet
592 * Return Value: None.
596 static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
597 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
600 WLAN_FR_REASSOCREQ sFrame;
602 struct vnt_tx_mgmt *pTxPacket;
603 u16 wAssocStatus = 0;
605 u32 uRateLen = WLAN_RATES_MAXLEN;
606 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
607 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
609 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
611 // node index not found
614 //check if node is authenticated
616 memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
617 sFrame.len = pRxPacket->cbMPDULen;
618 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
619 vMgrDecodeReassocRequest(&sFrame);
621 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
622 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
623 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
624 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
625 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
626 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
627 // Todo: check sta basic rate, if ap can't support, set status code
629 if (pDevice->byBBType == BB_TYPE_11B) {
630 uRateLen = WLAN_RATES_MAXLEN_11B;
633 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
634 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
635 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
637 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
638 if (pDevice->byBBType == BB_TYPE_11G) {
639 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
640 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
643 abyCurrExtSuppRates[1] = 0;
646 RATEvParseMaxRate((void *)pDevice,
647 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
648 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
649 false, // do not change our basic rate
650 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
651 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
652 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
653 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
654 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
658 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
659 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
660 // Todo: check sta preamble, if ap can't support, set status code
661 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
662 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
663 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
664 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
665 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
666 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
667 wAssocAID = (u16)uNodeIndex;
670 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
671 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
673 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
675 pDevice->bProtectMode = true;
676 pDevice->bNonERPPresent = true;
678 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
679 pDevice->bBarkerPreambleMd = true;
682 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
683 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
684 sFrame.pHdr->sA3.abyAddr2[0],
685 sFrame.pHdr->sA3.abyAddr2[1],
686 sFrame.pHdr->sA3.abyAddr2[2],
687 sFrame.pHdr->sA3.abyAddr2[3],
688 sFrame.pHdr->sA3.abyAddr2[4],
689 sFrame.pHdr->sA3.abyAddr2[5]
691 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
692 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
696 // assoc response reply..
697 pTxPacket = s_MgrMakeReAssocResponse
704 sFrame.pHdr->sA3.abyAddr2,
705 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
706 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
709 if (pTxPacket != NULL ){
711 if (pDevice->bEnableHostapd) {
714 Status = csMgmt_xmit(pDevice, pTxPacket);
715 if (Status != CMD_STATUS_PENDING) {
716 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
719 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
727 * Routine Description:
728 * Handle incoming association response frames.
735 static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
736 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
739 WLAN_FR_ASSOCRESP sFrame;
740 PWLAN_IE_SSID pItemSSID;
743 if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
744 pMgmt->eCurrState == WMAC_STATE_ASSOC) {
746 sFrame.len = pRxPacket->cbMPDULen;
747 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
749 vMgrDecodeAssocResponse(&sFrame);
750 if ((sFrame.pwCapInfo == NULL)
751 || (sFrame.pwStatus == NULL)
752 || (sFrame.pwAid == NULL)
753 || (sFrame.pSuppRates == NULL)) {
758 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
759 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
760 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
761 pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
763 pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
764 pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
765 pbyIEs = pMgmt->sAssocInfo.abyIEs;
766 pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
767 memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
769 // save values and set current BSS state
770 if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
772 pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
773 if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
775 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
777 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
778 pMgmt->eCurrState = WMAC_STATE_ASSOC;
779 BSSvUpdateAPNode((void *) pDevice,
782 sFrame.pExtSuppRates);
783 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
784 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
785 pDevice->bLinkPass = true;
786 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
788 //if(pDevice->bWPASuppWextEnabled == true)
792 union iwreq_data wrqu;
797 len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
799 memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
800 memset(&wrqu, 0, sizeof (wrqu));
801 wrqu.data.length = len;
802 we_event = IWEVASSOCREQIE;
803 PRINT_K("wireless_send_event--->IWEVASSOCREQIE\n");
804 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
808 len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
811 memcpy(buf, pbyIEs, len);
812 memset(&wrqu, 0, sizeof (wrqu));
813 wrqu.data.length = len;
814 we_event = IWEVASSOCRESPIE;
815 PRINT_K("wireless_send_event--->IWEVASSOCRESPIE\n");
816 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
819 memset(&wrqu, 0, sizeof (wrqu));
820 memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
821 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
822 PRINT_K("wireless_send_event--->SIOCGIWAP(associated)\n");
823 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
830 pMgmt->eCurrState = WMAC_STATE_IDLE;
833 // jump back to the auth state and indicate the error
834 pMgmt->eCurrState = WMAC_STATE_AUTH;
836 s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
841 //need clear flags related to Networkmanager
842 pDevice->bwextstep0 = false;
843 pDevice->bwextstep1 = false;
844 pDevice->bwextstep2 = false;
845 pDevice->bwextstep3 = false;
846 pDevice->bWPASuppWextEnabled = false;
848 if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
849 timer_expire(pDevice->sTimerCommand, 0);
856 * Routine Description:
857 * Start the station authentication procedure. Namely, send an
858 * authentication frame to the AP.
865 void vMgrAuthenBeginSta(struct vnt_private *pDevice,
866 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
868 WLAN_FR_AUTHEN sFrame;
869 struct vnt_tx_mgmt *pTxPacket =
870 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
872 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
873 + WLAN_AUTHEN_FR_MAXLEN);
874 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
875 + sizeof(struct vnt_tx_mgmt));
876 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
877 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
878 vMgrEncodeAuthen(&sFrame);
880 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
882 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
883 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
885 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
886 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
887 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
888 if (pMgmt->bShareKeyAlgorithm)
889 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
891 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
893 *(sFrame.pwAuthSequence) = cpu_to_le16(1);
894 /* Adjust the length fields */
895 pTxPacket->cbMPDULen = sFrame.len;
896 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
898 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
899 if (*pStatus == CMD_STATUS_PENDING){
900 pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
901 *pStatus = CMD_STATUS_SUCCESS;
909 * Routine Description:
910 * Start the station(AP) deauthentication procedure. Namely, send an
911 * deauthentication frame to the AP or Sta.
918 void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
919 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
922 WLAN_FR_DEAUTHEN sFrame;
923 struct vnt_tx_mgmt *pTxPacket =
924 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
926 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
927 + WLAN_DEAUTHEN_FR_MAXLEN);
928 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
929 + sizeof(struct vnt_tx_mgmt));
930 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
931 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
932 vMgrEncodeDeauthen(&sFrame);
934 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
936 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
937 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
940 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
941 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
942 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
944 *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
945 /* Adjust the length fields */
946 pTxPacket->cbMPDULen = sFrame.len;
947 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
949 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
950 if (*pStatus == CMD_STATUS_PENDING){
951 *pStatus = CMD_STATUS_SUCCESS;
959 * Routine Description:
960 * Handle incoming authentication frames.
967 static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
968 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
970 WLAN_FR_AUTHEN sFrame;
972 // we better be an AP or a STA in AUTHPENDING otherwise ignore
973 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
974 pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
979 sFrame.len = pRxPacket->cbMPDULen;
980 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
981 vMgrDecodeAuthen(&sFrame);
982 switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
985 s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
988 s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
992 s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
995 s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
999 cpu_to_le16((*(sFrame.pwAuthSequence))));
1007 * Routine Description:
1008 * Handles incoming authen frames with sequence 1. Currently
1009 * assumes we're an AP. So far, no one appears to use authentication
1017 static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
1018 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1020 struct vnt_tx_mgmt *pTxPacket = NULL;
1022 WLAN_FR_AUTHEN sFrame;
1023 PSKeyItem pTransmitKey;
1025 /* Insert a Node entry */
1026 if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2,
1028 BSSvCreateOneNode(pDevice, &uNodeIndex);
1029 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr,
1030 pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1033 if (pMgmt->bShareKeyAlgorithm) {
1034 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
1035 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
1038 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1042 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1043 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1044 + WLAN_AUTHEN_FR_MAXLEN);
1045 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1046 + sizeof(struct vnt_tx_mgmt));
1047 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
1048 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1049 // format buffer structure
1050 vMgrEncodeAuthen(&sFrame);
1052 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1054 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1055 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1056 WLAN_SET_FC_ISWEP(0)
1058 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1059 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1060 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1061 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1062 *(sFrame.pwAuthSequence) = cpu_to_le16(2);
1064 if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
1065 if (pMgmt->bShareKeyAlgorithm)
1066 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1068 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1071 if (pMgmt->bShareKeyAlgorithm)
1072 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1074 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1077 if (pMgmt->bShareKeyAlgorithm &&
1078 (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
1080 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1081 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1082 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1083 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1084 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1086 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
1087 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1088 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1090 memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
1093 /* Adjust the length fields */
1094 pTxPacket->cbMPDULen = sFrame.len;
1095 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1097 if (pDevice->bEnableHostapd) {
1100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
1101 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1102 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
1109 * Routine Description:
1110 * Handles incoming auth frames with sequence number 2. Currently
1111 * assumes we're a station.
1119 static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
1120 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1122 WLAN_FR_AUTHEN sFrame;
1123 struct vnt_tx_mgmt *pTxPacket = NULL;
1125 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
1127 case WLAN_AUTH_ALG_OPENSYSTEM:
1128 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1129 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
1130 pMgmt->eCurrState = WMAC_STATE_AUTH;
1131 timer_expire(pDevice->sTimerCommand, 0);
1134 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
1135 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1136 pMgmt->eCurrState = WMAC_STATE_IDLE;
1138 if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
1139 /* spin_unlock_irq(&pDevice->lock);
1140 vCommandTimerWait((void *) pDevice, 0);
1141 spin_lock_irq(&pDevice->lock); */
1145 case WLAN_AUTH_ALG_SHAREDKEY:
1147 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1148 pTxPacket = (struct vnt_tx_mgmt *)
1149 pMgmt->pbyMgmtPacketPool;
1150 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1151 + WLAN_AUTHEN_FR_MAXLEN);
1152 pTxPacket->p80211Header
1153 = (PUWLAN_80211HDR)((u8 *)pTxPacket
1154 + sizeof(struct vnt_tx_mgmt));
1155 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
1156 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1157 // format buffer structure
1158 vMgrEncodeAuthen(&sFrame);
1160 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1162 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1163 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1164 WLAN_SET_FC_ISWEP(1)
1166 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1167 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1168 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1169 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1170 *(sFrame.pwAuthSequence) = cpu_to_le16(3);
1171 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1172 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1173 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1174 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1175 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1176 memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
1177 // Adjust the length fields
1178 pTxPacket->cbMPDULen = sFrame.len;
1179 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1181 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
1184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
1187 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
1188 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1189 /* spin_unlock_irq(&pDevice->lock);
1190 vCommandTimerWait((void *) pDevice, 0);
1191 spin_lock_irq(&pDevice->lock); */
1193 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
1205 * Routine Description:
1206 * Handles incoming authen frames with sequence 3. Currently
1207 * assumes we're an AP. This function assumes the frame has
1208 * already been successfully decrypted.
1216 static void s_vMgrRxAuthenSequence_3(struct vnt_private *pDevice,
1217 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1219 struct vnt_tx_mgmt *pTxPacket = NULL;
1220 u32 uStatusCode = 0 ;
1222 WLAN_FR_AUTHEN sFrame;
1224 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1225 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1228 if (BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1229 if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
1230 uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
1233 if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
1234 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1239 uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
1244 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1245 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
1247 uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
1248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
1252 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1253 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1254 + WLAN_AUTHEN_FR_MAXLEN);
1255 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1256 + sizeof(struct vnt_tx_mgmt));
1257 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
1258 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1259 // format buffer structure
1260 vMgrEncodeAuthen(&sFrame);
1262 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1264 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1265 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1266 WLAN_SET_FC_ISWEP(0)
1268 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1269 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1270 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1271 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1272 *(sFrame.pwAuthSequence) = cpu_to_le16(4);
1273 *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
1275 /* Adjust the length fields */
1276 pTxPacket->cbMPDULen = sFrame.len;
1277 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1279 if (pDevice->bEnableHostapd) {
1282 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
1291 * Routine Description:
1292 * Handles incoming authen frames with sequence 4
1299 static void s_vMgrRxAuthenSequence_4(struct vnt_private *pDevice,
1300 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1303 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1304 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
1305 pMgmt->eCurrState = WMAC_STATE_AUTH;
1306 timer_expire(pDevice->sTimerCommand, 0);
1309 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
1310 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
1311 pMgmt->eCurrState = WMAC_STATE_IDLE;
1314 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1315 /* spin_unlock_irq(&pDevice->lock);
1316 vCommandTimerWait((void *) pDevice, 0);
1317 spin_lock_irq(&pDevice->lock); */
1323 * Routine Description:
1324 * Handles incoming disassociation frames
1332 static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
1333 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
1335 WLAN_FR_DISASSOC sFrame;
1337 CMD_STATUS CmdStatus;
1339 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1340 // if is acting an AP..
1341 // a STA is leaving this BSS..
1342 sFrame.len = pRxPacket->cbMPDULen;
1343 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
1344 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1345 BSSvRemoveOneNode(pDevice, uNodeIndex);
1348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
1351 else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
1352 sFrame.len = pRxPacket->cbMPDULen;
1353 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
1354 vMgrDecodeDisassociation(&sFrame);
1355 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
1357 pDevice->fWPA_Authened = false;
1359 //TODO: do something let upper layer know or
1360 //try to send associate packet again because of inactivity timeout
1361 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
1362 pDevice->bLinkPass = false;
1363 pMgmt->sNodeDBTable[0].bActive = false;
1364 pDevice->byReAssocCount = 0;
1365 pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state!
1366 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
1367 vMgrReAssocBeginSta(pDevice, pMgmt, &CmdStatus);
1368 if(CmdStatus == CMD_STATUS_PENDING) {
1369 pDevice->byReAssocCount ++;
1370 return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected!
1374 // if(pDevice->bWPASuppWextEnabled == true)
1376 union iwreq_data wrqu;
1377 memset(&wrqu, 0, sizeof (wrqu));
1378 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1379 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1380 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1383 /* else, ignore it */
1390 * Routine Description:
1391 * Handles incoming deauthentication frames
1399 static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
1400 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
1402 WLAN_FR_DEAUTHEN sFrame;
1405 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1407 // if is acting an AP..
1408 // a STA is leaving this BSS..
1409 sFrame.len = pRxPacket->cbMPDULen;
1410 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
1411 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1412 BSSvRemoveOneNode(pDevice, uNodeIndex);
1415 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
1419 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
1420 sFrame.len = pRxPacket->cbMPDULen;
1421 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
1422 vMgrDecodeDeauthen(&sFrame);
1423 pDevice->fWPA_Authened = false;
1424 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
1425 // TODO: update BSS list for specific BSSID if pre-authentication case
1426 if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3,
1427 pMgmt->abyCurrBSSID)) {
1428 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
1429 pMgmt->sNodeDBTable[0].bActive = false;
1430 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1431 pMgmt->eCurrState = WMAC_STATE_IDLE;
1432 netif_stop_queue(pDevice->dev);
1433 pDevice->bLinkPass = false;
1434 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1438 // if(pDevice->bWPASuppWextEnabled == true)
1440 union iwreq_data wrqu;
1441 memset(&wrqu, 0, sizeof (wrqu));
1442 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1443 PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
1444 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1448 /* else, ignore it. TODO: IBSS authentication service
1449 would be implemented here */
1456 * Routine Description:
1457 * check if current channel is match ZoneType.
1465 static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel)
1469 switch(pDevice->byZoneType) {
1470 case 0x00: //USA:1~11
1471 if((byCurrChannel<1) ||(byCurrChannel>11))
1474 case 0x01: //Japan:1~13
1475 case 0x02: //Europe:1~13
1476 if((byCurrChannel<1) ||(byCurrChannel>13))
1479 default: //reserve for other zonetype
1488 * Routine Description:
1489 * Handles and analysis incoming beacon frames.
1497 static void s_vMgrRxBeacon(struct vnt_private *pDevice,
1498 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
1502 WLAN_FR_BEACON sFrame;
1504 int bIsBSSIDEqual = false;
1505 int bIsSSIDEqual = false;
1506 int bTSFLargeDiff = false;
1507 int bTSFOffsetPostive = false;
1508 int bUpdateTSF = false;
1509 int bIsAPBeacon = false;
1510 int bIsChannelEqual = false;
1511 u32 uLocateByteIndex;
1515 u64 qwTimestamp, qwLocalTSF;
1517 u16 wStartIndex = 0;
1519 u8 byCurrChannel = pRxPacket->byRxChannel;
1521 u32 uRateLen = WLAN_RATES_MAXLEN;
1522 int bChannelHit = false;
1523 u8 byOldPreambleType;
1525 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
1528 memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
1529 sFrame.len = pRxPacket->cbMPDULen;
1530 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
1532 // decode the beacon frame
1533 vMgrDecodeBeacon(&sFrame);
1535 if ((sFrame.pwBeaconInterval == NULL)
1536 || (sFrame.pwCapInfo == NULL)
1537 || (sFrame.pSSID == NULL)
1538 || (sFrame.pSuppRates == NULL)) {
1540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
1544 if( byCurrChannel > CB_MAX_CHANNEL_24G )
1546 if (sFrame.pDSParms != NULL) {
1547 if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
1549 byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
1555 if (sFrame.pDSParms != NULL) {
1556 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
1558 byCurrChannel = sFrame.pDSParms->byCurrChannel;
1564 if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
1567 if (sFrame.pERP != NULL) {
1568 sERP.byERP = sFrame.pERP->byContext;
1569 sERP.bERPExist = true;
1572 sERP.bERPExist = false;
1576 pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
1577 sFrame.pHdr->sA3.abyAddr3,
1579 if (pBSSList == NULL) {
1580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
1581 BSSbInsertToBSSList((void *) pDevice,
1582 sFrame.pHdr->sA3.abyAddr3,
1583 *sFrame.pqwTimestamp,
1584 *sFrame.pwBeaconInterval,
1589 sFrame.pExtSuppRates,
1595 sFrame.len - WLAN_HDR_ADDR3_LEN,
1596 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
1597 (void *) pRxPacket);
1600 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
1601 BSSbUpdateToBSSList((void *) pDevice,
1602 *sFrame.pqwTimestamp,
1603 *sFrame.pwBeaconInterval,
1609 sFrame.pExtSuppRates,
1616 sFrame.len - WLAN_HDR_ADDR3_LEN,
1617 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
1618 (void *) pRxPacket);
1626 if(byCurrChannel == (u8)pMgmt->uCurrChannel)
1627 bIsChannelEqual = true;
1629 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1631 // if rx beacon without ERP field
1632 if (sERP.bERPExist) {
1633 if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
1634 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1635 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1639 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1640 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1643 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1644 if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
1645 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1647 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1651 // check if BSSID the same
1652 if (memcmp(sFrame.pHdr->sA3.abyAddr3,
1653 pMgmt->abyCurrBSSID,
1654 WLAN_BSSID_LEN) == 0) {
1656 bIsBSSIDEqual = true;
1657 pDevice->uCurrRSSI = pRxPacket->uRSSI;
1658 pDevice->byCurrSQ = pRxPacket->bySQ;
1659 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
1660 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1661 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
1664 // check if SSID the same
1665 if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
1666 if (memcmp(sFrame.pSSID->abySSID,
1667 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
1670 bIsSSIDEqual = true;
1674 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
1675 (bIsBSSIDEqual == true) &&
1676 (bIsSSIDEqual == true) &&
1677 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1678 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1679 // add state check to prevent reconnect fail since we'll receive Beacon
1682 if (pBSSList != NULL) {
1685 if ((pBSSList->sERP.bERPExist == true) && (pDevice->byBBType == BB_TYPE_11G)) {
1686 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
1687 pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1688 if (pDevice->bProtectMode) {
1689 MACvEnableProtectMD(pDevice);
1691 MACvDisableProtectMD(pDevice);
1693 vUpdateIFS(pDevice);
1695 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
1696 pDevice->bNonERPPresent = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1698 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
1699 pDevice->bBarkerPreambleMd = (pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
1700 //BarkerPreambleMd has higher priority than shortPreamble bit in Cap
1701 if (pDevice->bBarkerPreambleMd) {
1702 MACvEnableBarkerPreambleMd(pDevice);
1704 MACvDisableBarkerPreambleMd(pDevice);
1708 // Sync Short Slot Time
1709 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) {
1710 bool bShortSlotTime;
1712 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo);
1713 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
1714 //Kyle check if it is OK to set G.
1715 if (pDevice->byBBType == BB_TYPE_11A) {
1716 bShortSlotTime = true;
1718 else if (pDevice->byBBType == BB_TYPE_11B) {
1719 bShortSlotTime = false;
1721 if (bShortSlotTime != pDevice->bShortSlotTime) {
1722 pDevice->bShortSlotTime = bShortSlotTime;
1723 BBvSetShortSlotTime(pDevice);
1724 vUpdateIFS(pDevice);
1729 // Preamble may change dynamically
1731 byOldPreambleType = pDevice->byPreambleType;
1732 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pBSSList->wCapInfo)) {
1733 pDevice->byPreambleType = pDevice->byShortPreamble;
1736 pDevice->byPreambleType = 0;
1738 if (pDevice->byPreambleType != byOldPreambleType)
1739 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
1741 // Basic Rate Set may change dynamically
1743 if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
1744 uRateLen = WLAN_RATES_MAXLEN_11B;
1746 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
1747 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1749 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
1750 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1752 RATEvParseMaxRate((void *)pDevice,
1753 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1754 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1756 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
1757 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
1758 &(pMgmt->sNodeDBTable[0].wSuppRate),
1759 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
1760 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
1766 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
1767 // check if CF field exisit
1768 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
1769 if (sFrame.pCFParms->wCFPDurRemaining > 0) {
1770 // TODO: deal with CFP period to set NAV
1774 qwTimestamp = cpu_to_le64(*sFrame.pqwTimestamp);
1775 qwLocalTSF = pRxPacket->qwLocalTSF;
1777 // check if beacon TSF larger or small than our local TSF
1778 if (qwTimestamp >= qwLocalTSF)
1779 bTSFOffsetPostive = true;
1781 bTSFOffsetPostive = false;
1783 if (bTSFOffsetPostive) {
1784 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
1787 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
1790 if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
1791 bTSFLargeDiff = true;
1794 if (bIsAPBeacon == true) {
1796 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
1800 if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM)) {
1802 /* deal with DTIM, analysis TIM */
1803 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
1804 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
1805 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
1806 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
1808 // check if AID in TIM field bit on
1810 wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
1812 wAIDIndex = (wAIDNumber >> 3);
1813 if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
1814 uLocateByteIndex = wAIDIndex - wStartIndex;
1815 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
1816 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
1817 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
1818 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
1821 pMgmt->bInTIM = false;
1825 pMgmt->bInTIM = false;
1828 if (pMgmt->bInTIM ||
1829 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
1830 pMgmt->bInTIMWake = true;
1831 /* send out ps-poll packet */
1833 PSvSendPSPOLL(pDevice);
1837 pMgmt->bInTIMWake = false;
1838 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
1839 if (pDevice->bPWBitOn == false) {
1840 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
1841 if (PSbSendNullPacket(pDevice))
1842 pDevice->bPWBitOn = true;
1844 if(PSbConsiderPowerDown(pDevice, false, false)) {
1845 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
1853 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
1854 if (bIsBSSIDEqual) {
1855 // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
1856 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
1857 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1859 // adhoc mode:TSF updated only when beacon larger then local TSF
1860 if (bTSFLargeDiff && bTSFOffsetPostive &&
1861 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
1864 // During dpc, already in spinlocked.
1865 if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
1867 // Update the STA, (Technically the Beacons of all the IBSS nodes
1868 // should be identical, but that's not happening in practice.
1869 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1870 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1871 WLAN_RATES_MAXLEN_11B);
1872 RATEvParseMaxRate((void *)pDevice,
1873 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1876 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
1877 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
1878 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
1879 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
1880 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
1882 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
1883 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
1884 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
1887 /* Todo, initial Node content */
1888 BSSvCreateOneNode(pDevice, &uNodeIndex);
1890 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1891 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1892 WLAN_RATES_MAXLEN_11B);
1893 RATEvParseMaxRate((void *)pDevice,
1894 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1897 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
1898 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
1899 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
1900 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
1901 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
1904 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1905 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
1906 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
1908 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
1909 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
1910 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
1914 // if other stations jointed, indicate connect to upper layer..
1915 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
1916 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
1917 pMgmt->eCurrState = WMAC_STATE_JOINTED;
1918 pDevice->bLinkPass = true;
1919 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
1920 if (netif_queue_stopped(pDevice->dev)){
1921 netif_wake_queue(pDevice->dev);
1923 pMgmt->sNodeDBTable[0].bActive = true;
1924 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1928 else if (bIsSSIDEqual) {
1930 // See other adhoc sta with the same SSID but BSSID is different.
1931 // adpot this vars only when TSF larger then us.
1932 if (bTSFLargeDiff && bTSFOffsetPostive) {
1933 // we don't support ATIM under adhoc mode
1934 // if ( sFrame.pIBSSParms->wATIMWindow == 0) {
1936 // TODO: check sFrame cap if privacy on, and support rate syn
1937 memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
1938 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1939 pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
1940 pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
1941 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1942 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1943 WLAN_RATES_MAXLEN_11B);
1944 // set HW beacon interval and re-synchronizing....
1945 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
1947 MACvWriteBeaconInterval(pDevice, pMgmt->wCurrBeaconPeriod);
1948 CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
1949 CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
1951 // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
1952 MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
1954 byOldPreambleType = pDevice->byPreambleType;
1955 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo)) {
1956 pDevice->byPreambleType = pDevice->byShortPreamble;
1959 pDevice->byPreambleType = 0;
1961 if (pDevice->byPreambleType != byOldPreambleType)
1962 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
1964 // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
1965 // set highest basic rate
1966 // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
1967 // Prepare beacon frame
1968 bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
1976 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
1977 CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp , pRxPacket->qwLocalTSF);
1978 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
1979 CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
1987 * Routine Description:
1988 * Instructs the hw to create a bss using the supplied
1989 * attributes. Note that this implementation only supports Ad-Hoc
1998 void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
2000 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2003 u8 byTopCCKBasicRate;
2004 u8 byTopOFDMBasicRate;
2007 u8 abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C,
2009 u8 abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
2010 u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2013 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
2015 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2016 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
2017 (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
2018 (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
2019 // encryption mode error
2020 *pStatus = CMD_STATUS_FAILURE;
2025 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2026 pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
2028 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2029 pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
2031 if (pDevice->byBBType == BB_TYPE_11G)
2032 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2033 if (pDevice->byBBType == BB_TYPE_11B)
2034 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2035 if (pDevice->byBBType == BB_TYPE_11A)
2036 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2039 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
2040 pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
2041 pMgmt->abyCurrExtSuppRates[1] = 0;
2042 for (ii = 0; ii < 4; ii++)
2043 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2045 pMgmt->abyCurrSuppRates[1] = 8;
2046 pMgmt->abyCurrExtSuppRates[1] = 0;
2047 for (ii = 0; ii < 8; ii++)
2048 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2051 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2052 pMgmt->abyCurrSuppRates[1] = 8;
2053 pMgmt->abyCurrExtSuppRates[1] = 4;
2054 for (ii = 0; ii < 4; ii++)
2055 pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
2056 for (ii = 4; ii < 8; ii++)
2057 pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
2058 for (ii = 0; ii < 4; ii++)
2059 pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
2062 // Disable Protect Mode
2063 pDevice->bProtectMode = 0;
2064 MACvDisableProtectMD(pDevice);
2066 pDevice->bBarkerPreambleMd = 0;
2067 MACvDisableBarkerPreambleMd(pDevice);
2069 // Kyle Test 2003.11.04
2071 // set HW beacon interval
2072 if (pMgmt->wIBSSBeaconPeriod == 0)
2073 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
2074 MACvWriteBeaconInterval(pDevice, pMgmt->wIBSSBeaconPeriod);
2076 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
2077 // clear TSF counter
2078 CARDbClearCurrentTSF(pDevice);
2080 // enable TSF counter
2081 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTREN);
2083 CARDvSetFirstNextTBTT(pDevice, pMgmt->wIBSSBeaconPeriod);
2085 pMgmt->uIBSSChannel = pDevice->uChannel;
2087 if (pMgmt->uIBSSChannel == 0)
2088 pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
2090 // set channel and clear NAV
2091 CARDbSetMediaChannel(pDevice, pMgmt->uIBSSChannel);
2092 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2094 pDevice->byPreambleType = pDevice->byShortPreamble;
2098 RATEvParseMaxRate((void *)pDevice,
2099 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2100 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
2101 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2102 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2104 if (pDevice->byBBType == BB_TYPE_11A) {
2105 pDevice->bShortSlotTime = true;
2107 pDevice->bShortSlotTime = false;
2109 BBvSetShortSlotTime(pDevice);
2110 // vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called
2111 // after setting ShortSlotTime.
2112 // CARDvSetBSSMode call vUpdateIFS()
2113 CARDvSetBSSMode(pDevice);
2115 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2116 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_AP);
2117 pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
2120 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2121 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2122 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2125 // Adopt pre-configured IBSS vars to current vars
2126 pMgmt->eCurrState = WMAC_STATE_STARTED;
2127 pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
2128 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2129 pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
2130 pDevice->uCurrRSSI = 0;
2131 pDevice->byCurrSQ = 0;
2133 memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
2134 ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
2136 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2137 memcpy(pMgmt->abyCurrSSID,
2138 pMgmt->abyDesireSSID,
2139 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
2142 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2143 // AP mode BSSID = MAC addr
2144 memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2145 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:"
2146 "%pM\n", pMgmt->abyCurrBSSID);
2149 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2151 // BSSID selected must be randomized as spec 11.1.3
2152 pMgmt->abyCurrBSSID[5] = (u8)(qwCurrTSF & 0x000000ff);
2153 pMgmt->abyCurrBSSID[4] = (u8)((qwCurrTSF & 0x0000ff00) >> 8);
2154 pMgmt->abyCurrBSSID[3] = (u8)((qwCurrTSF & 0x00ff0000) >> 16);
2155 pMgmt->abyCurrBSSID[2] = (u8)((qwCurrTSF & 0x00000ff0) >> 4);
2156 pMgmt->abyCurrBSSID[1] = (u8)((qwCurrTSF & 0x000ff000) >> 12);
2157 pMgmt->abyCurrBSSID[0] = (u8)((qwCurrTSF & 0x0ff00000) >> 20);
2158 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2159 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2160 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
2161 pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
2162 pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
2163 pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
2164 pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
2165 pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
2167 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:"
2168 "%pM\n", pMgmt->abyCurrBSSID);
2172 MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
2173 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
2175 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2176 pDevice->byRxMode |= RCR_BSSID;
2177 pMgmt->bCurrBSSIDFilterOn = true;
2179 // Set Capability Info
2180 pMgmt->wCurrCapInfo = 0;
2182 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2183 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
2184 pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
2185 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2186 pDevice->eOPMode = OP_MODE_AP;
2189 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2190 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
2191 pDevice->eOPMode = OP_MODE_ADHOC;
2194 if (pDevice->bEncryptionEnable) {
2195 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
2196 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2197 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2198 pMgmt->byCSSPK = KEY_CTL_CCMP;
2199 pMgmt->byCSSGK = KEY_CTL_CCMP;
2200 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2201 pMgmt->byCSSPK = KEY_CTL_TKIP;
2202 pMgmt->byCSSGK = KEY_CTL_TKIP;
2204 pMgmt->byCSSPK = KEY_CTL_NONE;
2205 pMgmt->byCSSGK = KEY_CTL_WEP;
2208 pMgmt->byCSSPK = KEY_CTL_WEP;
2209 pMgmt->byCSSGK = KEY_CTL_WEP;
2213 pMgmt->byERPContext = 0;
2215 if (pDevice->byPreambleType == 1) {
2216 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
2218 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
2221 pMgmt->eCurrState = WMAC_STATE_STARTED;
2222 // Prepare beacon to send
2223 if (bMgrPrepareBeaconToSend((void *) pDevice, pMgmt))
2224 *pStatus = CMD_STATUS_SUCCESS;
2231 * Routine Description:
2232 * Instructs wmac to join a bss using the supplied attributes.
2233 * The arguments may the BSSID or SSID and the rest of the
2234 * attributes are obtained from the scan result of known bss list.
2242 void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
2244 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2245 PKnownBSS pCurr = NULL;
2247 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2248 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2249 PWLAN_IE_SSID pItemSSID;
2250 u32 uRateLen = WLAN_RATES_MAXLEN;
2251 u16 wMaxBasicRate = RATE_1M;
2252 u16 wMaxSuppRate = RATE_1M;
2254 u8 byTopCCKBasicRate = RATE_1M;
2255 u8 byTopOFDMBasicRate = RATE_1M;
2256 u8 bShortSlotTime = false;
2258 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
2259 if (pMgmt->sBSSList[ii].bActive == true)
2263 if (ii == MAX_BSS_NUM) {
2264 *pStatus = CMD_STATUS_RESOURCES;
2265 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
2269 // memset(pMgmt->abyDesireBSSID, 0, WLAN_BSSID_LEN);
2270 // Search known BSS list for prefer BSSID or SSID
2272 pCurr = BSSpSearchBSSList(pDevice,
2273 pMgmt->abyDesireBSSID,
2274 pMgmt->abyDesireSSID,
2275 pDevice->eConfigPHYMode
2279 *pStatus = CMD_STATUS_RESOURCES;
2280 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
2281 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
2285 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
2287 if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
2289 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
2290 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2292 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2293 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
2294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2295 // encryption mode error
2296 pMgmt->eCurrState = WMAC_STATE_IDLE;
2299 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2300 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
2301 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2302 // encryption mode error
2303 pMgmt->eCurrState = WMAC_STATE_IDLE;
2310 //if(pDevice->bWPASuppWextEnabled == true)
2311 Encyption_Rebuild(pDevice, pCurr);
2313 // Infrastructure BSS
2314 s_vMgrSynchBSS(pDevice,
2320 if (*pStatus == CMD_STATUS_SUCCESS){
2322 // Adopt this BSS state vars in Mgmt Object
2323 pMgmt->uCurrChannel = pCurr->uChannel;
2325 memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2326 memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2328 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2329 uRateLen = WLAN_RATES_MAXLEN_11B;
2332 pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
2333 pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
2335 // Parse Support Rate IE
2336 pItemRates->byElementID = WLAN_EID_SUPP_RATES;
2337 pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2341 // Parse Extension Support Rate IE
2342 pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
2343 pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
2347 if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
2348 for (ii = 0; ii < (unsigned int) (8 - pItemRates->len); ) {
2349 pItemRates->abyRates[pItemRates->len + ii] =
2350 pItemExtRates->abyRates[ii];
2352 if (pItemExtRates->len <= ii)
2355 pItemRates->len += (u8)ii;
2356 if (pItemExtRates->len - ii > 0) {
2357 pItemExtRates->len -= (u8)ii;
2358 for (uu = 0; uu < pItemExtRates->len; uu ++) {
2359 pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
2362 pItemExtRates->len = 0;
2366 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
2367 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2368 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2369 vUpdateIFS(pDevice);
2370 // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
2371 // TODO: deal with if wCapInfo the PS-Pollable is on.
2372 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2373 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2374 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2375 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2377 pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
2379 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2380 // Adopt BSS state in Adapter Device Object
2381 pDevice->eOPMode = OP_MODE_INFRASTRUCTURE;
2382 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2384 // Add current BSS to Candidate list
2385 // This should only work for WPA2 BSS, and WPA2 BSS check must be done before.
2386 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
2387 bool bResult = bAdd_PMKID_Candidate((void *) pDevice,
2388 pMgmt->abyCurrBSSID,
2389 &pCurr->sRSNCapObj);
2390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
2391 if (bResult == false) {
2392 vFlush_PMKID_Candidate((void *) pDevice);
2393 DBG_PRT(MSG_LEVEL_DEBUG,
2394 KERN_INFO "vFlush_PMKID_Candidate: 4\n");
2395 bAdd_PMKID_Candidate((void *) pDevice,
2396 pMgmt->abyCurrBSSID,
2397 &pCurr->sRSNCapObj);
2401 // Preamble type auto-switch: if AP can receive short-preamble cap,
2402 // we can turn on too.
2403 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
2404 pDevice->byPreambleType = pDevice->byShortPreamble;
2407 pDevice->byPreambleType = 0;
2409 // Change PreambleType must set RSPINF again
2410 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
2412 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
2414 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11G) {
2416 if ((pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
2417 pDevice->bProtectMode = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
2418 if (pDevice->bProtectMode) {
2419 MACvEnableProtectMD(pDevice);
2421 MACvDisableProtectMD(pDevice);
2423 vUpdateIFS(pDevice);
2425 if ((pCurr->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
2426 pDevice->bNonERPPresent = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
2428 if ((pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
2429 pDevice->bBarkerPreambleMd = (pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
2430 //BarkerPreambleMd has higher priority than shortPreamble bit in Cap
2431 if (pDevice->bBarkerPreambleMd) {
2432 MACvEnableBarkerPreambleMd(pDevice);
2434 MACvDisableBarkerPreambleMd(pDevice);
2438 //DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo));
2439 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) {
2440 if (pDevice->byBBType == BB_TYPE_11A) {
2441 bShortSlotTime = true;
2443 else if (pDevice->byBBType == BB_TYPE_11B) {
2444 bShortSlotTime = false;
2447 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo);
2449 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
2450 if (bShortSlotTime != pDevice->bShortSlotTime) {
2451 pDevice->bShortSlotTime = bShortSlotTime;
2452 BBvSetShortSlotTime(pDevice);
2453 vUpdateIFS(pDevice);
2457 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
2460 pMgmt->eCurrState = WMAC_STATE_IDLE;
2466 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2468 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2470 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
2471 // encryption mode error
2472 pMgmt->eCurrState = WMAC_STATE_IDLE;
2476 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2478 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
2479 // encryption mode error
2480 pMgmt->eCurrState = WMAC_STATE_IDLE;
2485 // encryption mode error
2486 pMgmt->eCurrState = WMAC_STATE_IDLE;
2491 s_vMgrSynchBSS(pDevice,
2497 if (*pStatus == CMD_STATUS_SUCCESS){
2498 // Adopt this BSS state vars in Mgmt Object
2499 // TODO: check if CapInfo privacy on, but we don't..
2500 pMgmt->uCurrChannel = pCurr->uChannel;
2502 // Parse Support Rate IE
2503 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2504 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2505 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2506 WLAN_RATES_MAXLEN_11B);
2508 RATEvParseMaxRate((void *)pDevice,
2509 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2510 NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2511 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2512 vUpdateIFS(pDevice);
2513 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
2514 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2515 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2516 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2517 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2518 // pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
2519 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2520 pMgmt->eCurrState = WMAC_STATE_STARTED;
2521 // Adopt BSS state in Adapter Device Object
2522 pDevice->eOPMode = OP_MODE_ADHOC;
2523 pDevice->bLinkPass = true;
2524 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
2525 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2527 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%pM\n",
2528 pMgmt->abyCurrBSSID);
2529 // Preamble type auto-switch: if AP can receive short-preamble cap,
2530 // and if registry setting is short preamble we can turn on too.
2532 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
2533 pDevice->byPreambleType = pDevice->byShortPreamble;
2536 pDevice->byPreambleType = 0;
2538 // Change PreambleType must set RSPINF again
2539 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
2542 bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
2545 pMgmt->eCurrState = WMAC_STATE_IDLE;
2553 * Routine Description:
2554 * Set HW to synchronize a specific BSS from known BSS list.
2561 static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode,
2562 PKnownBSS pCurr, PCMD_STATUS pStatus)
2564 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2565 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
2566 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
2567 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
2568 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
2569 4, 0x0C, 0x12, 0x18, 0x60};
2570 /* 6M, 9M, 12M, 48M*/
2571 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
2572 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2573 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
2574 4, 0x02, 0x04, 0x0B, 0x16};
2576 *pStatus = CMD_STATUS_FAILURE;
2578 if (s_bCipherMatch(pCurr,
2579 pDevice->eEncryptionStatus,
2581 &(pMgmt->byCSSGK)) == false) {
2582 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n");
2586 pMgmt->pCurrBSS = pCurr;
2588 // if previous mode is IBSS.
2589 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2590 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
2593 // Init the BSS informations
2594 pDevice->bCCK = true;
2595 pDevice->bProtectMode = false;
2596 MACvDisableProtectMD(pDevice);
2597 pDevice->bBarkerPreambleMd = false;
2598 MACvDisableBarkerPreambleMd(pDevice);
2599 pDevice->bNonERPPresent = false;
2600 pDevice->byPreambleType = 0;
2601 pDevice->wBasicRate = 0;
2603 CARDbAddBasicRate((void *)pDevice, RATE_1M);
2605 // calculate TSF offset
2606 // TSF Offset = Received Timestamp TSF - Marked Local's TSF
2607 CARDvAdjustTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
2609 // set HW beacon interval
2610 MACvWriteBeaconInterval(pDevice, pCurr->wBeaconInterval);
2613 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2614 CARDvSetFirstNextTBTT(pDevice, pCurr->wBeaconInterval);
2617 MACvWriteBSSIDAddress(pDevice, pCurr->abyBSSID);
2619 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, 6);
2621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = "
2622 "%pM\n", pMgmt->abyCurrBSSID);
2624 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
2625 if ((pDevice->eConfigPHYMode == PHY_TYPE_11A) ||
2626 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2627 pDevice->byBBType = BB_TYPE_11A;
2628 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2629 pDevice->bShortSlotTime = true;
2630 BBvSetShortSlotTime(pDevice);
2631 CARDvSetBSSMode(pDevice);
2635 } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2636 if ((pDevice->eConfigPHYMode == PHY_TYPE_11B) ||
2637 (pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
2638 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2639 pDevice->byBBType = BB_TYPE_11B;
2640 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2641 pDevice->bShortSlotTime = false;
2642 BBvSetShortSlotTime(pDevice);
2643 CARDvSetBSSMode(pDevice);
2648 if ((pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
2649 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2650 pDevice->byBBType = BB_TYPE_11G;
2651 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2652 pDevice->bShortSlotTime = true;
2653 BBvSetShortSlotTime(pDevice);
2654 CARDvSetBSSMode(pDevice);
2655 } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) {
2656 pDevice->byBBType = BB_TYPE_11B;
2657 pDevice->bShortSlotTime = false;
2658 BBvSetShortSlotTime(pDevice);
2659 CARDvSetBSSMode(pDevice);
2665 if (uBSSMode == WMAC_MODE_ESS_STA) {
2666 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2667 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2668 pDevice->byRxMode |= RCR_BSSID;
2669 pMgmt->bCurrBSSIDFilterOn = true;
2672 // set channel and clear NAV
2673 CARDbSetMediaChannel(pDevice, pCurr->uChannel);
2674 pMgmt->uCurrChannel = pCurr->uChannel;
2675 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
2677 if ((pDevice->bUpdateBBVGA) &&
2678 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
2679 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
2680 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
2681 BBvSetShortSlotTime(pDevice);
2685 // 1. In Ad-hoc mode : check if received others beacon as jointed indication,
2686 // otherwise we will start own IBSS.
2687 // 2. In Infra mode : Supposed we already synchronized with AP right now.
2689 if (uBSSMode == WMAC_MODE_IBSS_STA) {
2690 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2691 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2692 pDevice->byRxMode |= RCR_BSSID;
2693 pMgmt->bCurrBSSIDFilterOn = true;
2696 if (pDevice->byBBType == BB_TYPE_11A) {
2697 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
2698 pMgmt->abyCurrExtSuppRates[1] = 0;
2699 } else if (pDevice->byBBType == BB_TYPE_11B) {
2700 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
2701 pMgmt->abyCurrExtSuppRates[1] = 0;
2703 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
2704 memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
2706 pMgmt->byERPContext = pCurr->sERP.byERP;
2708 *pStatus = CMD_STATUS_SUCCESS;
2713 static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr)
2715 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2717 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
2718 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
2719 if (pCurr->bWPAValid == true) { /*WPA-PSK */
2720 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
2721 if(pCurr->abyPKType[0] == WPA_TKIP) {
2722 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2723 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
2725 else if(pCurr->abyPKType[0] == WPA_AESCCMP) {
2726 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2727 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
2730 else if(pCurr->bWPA2Valid == true) { //WPA2-PSK
2731 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
2732 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
2733 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2734 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
2736 else if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
2737 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2738 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
2748 * Routine Description:
2757 static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
2759 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2762 int bStartFound = false;
2763 int bMulticast = false;
2764 u16 wStartIndex = 0;
2767 // Find size of partial virtual bitmap
2768 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
2769 byMap = pMgmt->abyPSTxMap[ii];
2771 // Mask out the broadcast bit which is indicated separately.
2772 bMulticast = (byMap & byMask[0]) != 0;
2774 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2781 wStartIndex = (u16)ii;
2783 wEndIndex = (u16)ii;
2787 // Round start index down to nearest even number
2788 wStartIndex &= ~BIT0;
2790 // Round end index up to nearest even number
2791 wEndIndex = ((wEndIndex + 1) & ~BIT0);
2793 // Size of element payload
2795 pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
2797 // Fill in the Fixed parts of the TIM
2798 pTIM->byDTIMCount = pMgmt->byDTIMCount;
2799 pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
2800 pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
2801 (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
2803 // Append variable part of TIM
2805 for (ii = wStartIndex, jj =0 ; ii <= wEndIndex; ii++, jj++) {
2806 pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
2809 // Aid = 0 don't used.
2810 pTIM->byVirtBitMap[0] &= ~BIT0;
2815 * Routine Description:
2816 * Constructs an Beacon frame( Ad-hoc mode)
2820 * PTR to frame; or NULL on allocation failure
2824 static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
2825 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
2826 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
2827 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
2828 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
2830 struct vnt_tx_mgmt *pTxPacket = NULL;
2831 WLAN_FR_BEACON sFrame;
2832 u8 abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2834 /* prepare beacon frame */
2835 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
2836 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
2837 + WLAN_BEACON_FR_MAXLEN);
2838 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2839 + sizeof(struct vnt_tx_mgmt));
2840 // Setup the sFrame structure.
2841 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
2842 sFrame.len = WLAN_BEACON_FR_MAXLEN;
2843 vMgrEncodeBeacon(&sFrame);
2845 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
2847 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
2848 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
2851 if (pDevice->bEnablePSMode) {
2852 sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((u16)WLAN_SET_FC_PWRMGT(1));
2855 memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
2856 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2857 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
2858 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
2859 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
2861 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
2862 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
2863 memcpy(sFrame.pSSID,
2865 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
2867 // Copy the rate set
2868 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2869 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
2870 memcpy(sFrame.pSuppRates,
2872 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
2875 if (pDevice->byBBType != BB_TYPE_11A) {
2876 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
2877 sFrame.len += (1) + WLAN_IEHDR_LEN;
2878 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
2879 sFrame.pDSParms->len = 1;
2880 sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
2883 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2884 sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
2885 sFrame.pTIM->byElementID = WLAN_EID_TIM;
2886 s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
2887 sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
2890 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2893 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
2894 sFrame.len += (2) + WLAN_IEHDR_LEN;
2895 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
2896 sFrame.pIBSSParms->len = 2;
2897 sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
2898 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2900 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
2901 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
2902 sFrame.pRSNWPA->len = 12;
2903 sFrame.pRSNWPA->abyOUI[0] = 0x00;
2904 sFrame.pRSNWPA->abyOUI[1] = 0x50;
2905 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
2906 sFrame.pRSNWPA->abyOUI[3] = 0x01;
2907 sFrame.pRSNWPA->wVersion = 1;
2908 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
2909 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
2910 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
2911 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
2912 sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
2913 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
2914 sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
2915 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
2916 sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
2918 sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
2920 // Pairwise Key Cipher Suite
2921 sFrame.pRSNWPA->wPKCount = 0;
2922 // Auth Key Management Suite
2923 *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
2924 sFrame.pRSNWPA->len +=2;
2927 *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
2928 sFrame.pRSNWPA->len +=2;
2929 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
2933 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2934 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
2935 sFrame.len += 1 + WLAN_IEHDR_LEN;
2936 sFrame.pERP->byElementID = WLAN_EID_ERP;
2937 sFrame.pERP->len = 1;
2938 sFrame.pERP->byContext = 0;
2939 if (pDevice->bProtectMode == true)
2940 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
2941 if (pDevice->bNonERPPresent == true)
2942 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
2943 if (pDevice->bBarkerPreambleMd == true)
2944 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
2946 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
2947 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2948 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2949 memcpy(sFrame.pExtSuppRates,
2951 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2954 // hostapd wpa/wpa2 IE
2955 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
2956 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2957 if (pMgmt->wWPAIELen != 0) {
2958 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
2959 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
2960 sFrame.len += pMgmt->wWPAIELen;
2965 /* Adjust the length fields */
2966 pTxPacket->cbMPDULen = sFrame.len;
2967 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
2974 * Routine Description:
2975 * Constructs an Prob-response frame
2979 * PTR to frame; or NULL on allocation failure
2983 struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
2984 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
2985 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
2986 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
2987 PWLAN_IE_SUPP_RATES pCurrSuppRates,
2988 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType)
2990 struct vnt_tx_mgmt *pTxPacket = NULL;
2991 WLAN_FR_PROBERESP sFrame;
2993 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
2994 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
2995 + WLAN_PROBERESP_FR_MAXLEN);
2996 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2997 + sizeof(struct vnt_tx_mgmt));
2998 // Setup the sFrame structure.
2999 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
3000 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
3001 vMgrEncodeProbeResponse(&sFrame);
3003 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3005 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3006 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
3008 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3009 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3010 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3011 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3012 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3014 if (byPHYType == BB_TYPE_11B) {
3015 *sFrame.pwCapInfo &= cpu_to_le16((u16)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
3019 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3020 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3021 memcpy(sFrame.pSSID,
3023 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3025 // Copy the rate set
3026 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3028 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3029 memcpy(sFrame.pSuppRates,
3031 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3035 if (pDevice->byBBType != BB_TYPE_11A) {
3036 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3037 sFrame.len += (1) + WLAN_IEHDR_LEN;
3038 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3039 sFrame.pDSParms->len = 1;
3040 sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
3043 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3045 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3046 sFrame.len += (2) + WLAN_IEHDR_LEN;
3047 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3048 sFrame.pIBSSParms->len = 2;
3049 sFrame.pIBSSParms->wATIMWindow = 0;
3051 if (pDevice->byBBType == BB_TYPE_11G) {
3052 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3053 sFrame.len += 1 + WLAN_IEHDR_LEN;
3054 sFrame.pERP->byElementID = WLAN_EID_ERP;
3055 sFrame.pERP->len = 1;
3056 sFrame.pERP->byContext = 0;
3057 if (pDevice->bProtectMode == true)
3058 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3059 if (pDevice->bNonERPPresent == true)
3060 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3061 if (pDevice->bBarkerPreambleMd == true)
3062 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3065 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3066 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3067 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3068 memcpy(sFrame.pExtSuppRates,
3070 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3074 // hostapd wpa/wpa2 IE
3075 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
3076 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3077 if (pMgmt->wWPAIELen != 0) {
3078 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3079 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3080 sFrame.len += pMgmt->wWPAIELen;
3085 // Adjust the length fields
3086 pTxPacket->cbMPDULen = sFrame.len;
3087 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3094 * Routine Description:
3095 * Constructs an association request frame
3099 * A ptr to frame or NULL on allocation failue
3103 struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
3104 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3105 u16 wListenInterval,
3106 PWLAN_IE_SSID pCurrSSID,
3107 PWLAN_IE_SUPP_RATES pCurrRates,
3108 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3110 struct vnt_tx_mgmt *pTxPacket = NULL;
3111 WLAN_FR_ASSOCREQ sFrame;
3115 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3116 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3117 + WLAN_ASSOCREQ_FR_MAXLEN);
3118 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3119 + sizeof(struct vnt_tx_mgmt));
3120 // Setup the sFrame structure.
3121 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
3122 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
3123 // format fixed field frame structure
3124 vMgrEncodeAssocRequest(&sFrame);
3126 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3128 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3129 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
3131 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3132 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3133 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3135 // Set the capability and listen interval
3136 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3137 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3139 // sFrame.len point to end of fixed field
3140 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3141 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3142 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3144 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3145 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3146 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3147 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3148 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3150 // Copy the rate set
3151 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3152 if ((pDevice->byBBType == BB_TYPE_11B) && (pCurrRates->len > 4))
3153 sFrame.len += 4 + WLAN_IEHDR_LEN;
3155 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3156 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3158 // Copy the extension rate set
3159 if ((pDevice->byBBType == BB_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3160 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3161 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3162 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3165 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3166 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3167 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3169 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3170 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3171 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3172 (pMgmt->pCurrBSS != NULL)) {
3174 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3175 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3176 sFrame.pRSNWPA->len = 16;
3177 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3178 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3179 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3180 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3181 sFrame.pRSNWPA->wVersion = 1;
3182 //Group Key Cipher Suite
3183 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3184 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3185 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3186 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3187 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3188 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3189 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3190 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3191 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3193 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3195 // Pairwise Key Cipher Suite
3196 sFrame.pRSNWPA->wPKCount = 1;
3197 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3198 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3199 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3200 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3201 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3202 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3203 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3205 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3207 // Auth Key Management Suite
3208 pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
3215 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3216 *pbyRSN++=WPA_AUTH_PSK;
3218 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3219 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3225 sFrame.pRSNWPA->len +=6;
3231 sFrame.pRSNWPA->len +=2;
3233 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3234 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3235 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3236 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
3237 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3239 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3240 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3241 (pMgmt->pCurrBSS != NULL)) {
3246 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3247 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3248 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3249 sFrame.pRSN->wVersion = 1;
3250 //Group Key Cipher Suite
3251 sFrame.pRSN->abyRSN[0] = 0x00;
3252 sFrame.pRSN->abyRSN[1] = 0x0F;
3253 sFrame.pRSN->abyRSN[2] = 0xAC;
3254 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3255 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3256 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3257 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3258 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3259 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3261 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3264 // Pairwise Key Cipher Suite
3265 sFrame.pRSN->abyRSN[4] = 1;
3266 sFrame.pRSN->abyRSN[5] = 0;
3267 sFrame.pRSN->abyRSN[6] = 0x00;
3268 sFrame.pRSN->abyRSN[7] = 0x0F;
3269 sFrame.pRSN->abyRSN[8] = 0xAC;
3270 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3271 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3272 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3273 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3274 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3275 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3277 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3279 sFrame.pRSN->len += 6;
3281 // Auth Key Management Suite
3282 sFrame.pRSN->abyRSN[10] = 1;
3283 sFrame.pRSN->abyRSN[11] = 0;
3284 sFrame.pRSN->abyRSN[12] = 0x00;
3285 sFrame.pRSN->abyRSN[13] = 0x0F;
3286 sFrame.pRSN->abyRSN[14] = 0xAC;
3287 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3288 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3289 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3290 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3292 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3294 sFrame.pRSN->len +=6;
3297 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3298 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3300 sFrame.pRSN->abyRSN[16] = 0;
3301 sFrame.pRSN->abyRSN[17] = 0;
3303 sFrame.pRSN->len +=2;
3305 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3307 pbyRSN = &sFrame.pRSN->abyRSN[18];
3308 pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
3309 *pwPMKID = 0; // Initialize PMKID count
3310 pbyRSN += 2; // Point to PMKID list
3311 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3312 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0],
3313 pMgmt->abyCurrBSSID,
3317 pDevice->gsPMKID.BSSIDInfo[ii].PMKID,
3322 if (*pwPMKID != 0) {
3323 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3327 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3328 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3329 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3330 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
3331 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3334 // Adjust the length fields
3335 pTxPacket->cbMPDULen = sFrame.len;
3336 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3342 * Routine Description:
3343 * Constructs an re-association request frame
3347 * A ptr to frame or NULL on allocation failure
3351 struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
3352 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3353 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
3354 PWLAN_IE_SUPP_RATES pCurrRates,
3355 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3357 struct vnt_tx_mgmt *pTxPacket = NULL;
3358 WLAN_FR_REASSOCREQ sFrame;
3362 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3363 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3364 + WLAN_REASSOCREQ_FR_MAXLEN);
3365 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3366 + sizeof(struct vnt_tx_mgmt));
3367 /* Setup the sFrame structure. */
3368 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
3369 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
3371 // format fixed field frame structure
3372 vMgrEncodeReassocRequest(&sFrame);
3374 /* Setup the header */
3375 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3377 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3378 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
3380 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3381 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3382 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3384 /* Set the capability and listen interval */
3385 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3386 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3388 memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3390 /* sFrame.len point to end of fixed field */
3391 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3392 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3393 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3395 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3396 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3397 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3398 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3399 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3401 /* Copy the rate set */
3402 /* sFrame.len point to end of SSID */
3403 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3404 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3405 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3407 // Copy the extension rate set
3408 if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3409 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3410 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3411 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3414 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3415 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3416 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3418 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3419 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3420 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3421 (pMgmt->pCurrBSS != NULL)) {
3423 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3424 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3425 sFrame.pRSNWPA->len = 16;
3426 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3427 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3428 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3429 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3430 sFrame.pRSNWPA->wVersion = 1;
3431 //Group Key Cipher Suite
3432 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3433 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3434 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3435 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3436 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3437 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3438 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3439 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3440 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3442 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3444 // Pairwise Key Cipher Suite
3445 sFrame.pRSNWPA->wPKCount = 1;
3446 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3447 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3448 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3449 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3450 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3451 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3452 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3454 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3456 // Auth Key Management Suite
3457 pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
3464 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3465 *pbyRSN++=WPA_AUTH_PSK;
3466 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3467 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3472 sFrame.pRSNWPA->len +=6;
3477 sFrame.pRSNWPA->len +=2;
3479 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3480 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3481 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3482 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
3483 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3485 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3486 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3487 (pMgmt->pCurrBSS != NULL)) {
3492 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3493 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3494 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3495 sFrame.pRSN->wVersion = 1;
3496 //Group Key Cipher Suite
3497 sFrame.pRSN->abyRSN[0] = 0x00;
3498 sFrame.pRSN->abyRSN[1] = 0x0F;
3499 sFrame.pRSN->abyRSN[2] = 0xAC;
3500 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3501 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3502 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3503 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3504 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3505 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3507 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3510 // Pairwise Key Cipher Suite
3511 sFrame.pRSN->abyRSN[4] = 1;
3512 sFrame.pRSN->abyRSN[5] = 0;
3513 sFrame.pRSN->abyRSN[6] = 0x00;
3514 sFrame.pRSN->abyRSN[7] = 0x0F;
3515 sFrame.pRSN->abyRSN[8] = 0xAC;
3516 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3517 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3518 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3519 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3520 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3521 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3523 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3525 sFrame.pRSN->len += 6;
3527 // Auth Key Management Suite
3528 sFrame.pRSN->abyRSN[10] = 1;
3529 sFrame.pRSN->abyRSN[11] = 0;
3530 sFrame.pRSN->abyRSN[12] = 0x00;
3531 sFrame.pRSN->abyRSN[13] = 0x0F;
3532 sFrame.pRSN->abyRSN[14] = 0xAC;
3533 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3534 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3535 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3536 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3538 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3540 sFrame.pRSN->len +=6;
3543 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3544 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3546 sFrame.pRSN->abyRSN[16] = 0;
3547 sFrame.pRSN->abyRSN[17] = 0;
3549 sFrame.pRSN->len +=2;
3551 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3553 pbyRSN = &sFrame.pRSN->abyRSN[18];
3554 pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
3555 *pwPMKID = 0; // Initialize PMKID count
3556 pbyRSN += 2; // Point to PMKID list
3557 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3558 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0],
3559 pMgmt->abyCurrBSSID,
3563 pDevice->gsPMKID.BSSIDInfo[ii].PMKID,
3568 if (*pwPMKID != 0) {
3569 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3573 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3574 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3575 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3576 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
3577 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3580 /* Adjust the length fields */
3581 pTxPacket->cbMPDULen = sFrame.len;
3582 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3589 * Routine Description:
3590 * Constructs an assoc-response frame
3594 * PTR to frame; or NULL on allocation failure
3598 struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
3599 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3600 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3601 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3603 struct vnt_tx_mgmt *pTxPacket = NULL;
3604 WLAN_FR_ASSOCRESP sFrame;
3606 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3607 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3608 + WLAN_ASSOCREQ_FR_MAXLEN);
3609 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3610 + sizeof(struct vnt_tx_mgmt));
3611 // Setup the sFrame structure
3612 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
3613 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3614 vMgrEncodeAssocResponse(&sFrame);
3616 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3618 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3619 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
3621 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3622 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3623 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3625 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3626 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
3627 *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
3629 // Copy the rate set
3630 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3631 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3632 memcpy(sFrame.pSuppRates,
3634 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3637 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3638 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3639 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3640 memcpy(sFrame.pExtSuppRates,
3642 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3646 // Adjust the length fields
3647 pTxPacket->cbMPDULen = sFrame.len;
3648 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3655 * Routine Description:
3656 * Constructs an reassoc-response frame
3660 * PTR to frame; or NULL on allocation failure
3664 struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
3665 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3666 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3667 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3669 struct vnt_tx_mgmt *pTxPacket = NULL;
3670 WLAN_FR_REASSOCRESP sFrame;
3672 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3673 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3674 + WLAN_ASSOCREQ_FR_MAXLEN);
3675 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3676 + sizeof(struct vnt_tx_mgmt));
3677 // Setup the sFrame structure
3678 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
3679 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3680 vMgrEncodeReassocResponse(&sFrame);
3682 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3684 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3685 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
3687 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3688 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3689 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3691 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3692 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
3693 *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
3695 // Copy the rate set
3696 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3697 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3698 memcpy(sFrame.pSuppRates,
3700 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3703 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3704 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3705 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3706 memcpy(sFrame.pExtSuppRates,
3708 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3712 // Adjust the length fields
3713 pTxPacket->cbMPDULen = sFrame.len;
3714 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3721 * Routine Description:
3722 * Handles probe response management frames.
3730 static void s_vMgrRxProbeResponse(struct vnt_private *pDevice,
3731 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
3733 PKnownBSS pBSSList = NULL;
3734 WLAN_FR_PROBERESP sFrame;
3735 u8 byCurrChannel = pRxPacket->byRxChannel;
3737 int bChannelHit = true;
3739 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
3741 sFrame.len = pRxPacket->cbMPDULen;
3742 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
3743 vMgrDecodeProbeResponse(&sFrame);
3745 if ((sFrame.pqwTimestamp == NULL)
3746 || (sFrame.pwBeaconInterval == NULL)
3747 || (sFrame.pwCapInfo == NULL)
3748 || (sFrame.pSSID == NULL)
3749 || (sFrame.pSuppRates == NULL)) {
3751 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p]\n",
3752 pRxPacket->p80211Header);
3757 if(sFrame.pSSID->len == 0)
3758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
3760 //{{ RobertYu:20050201, 11a byCurrChannel != sFrame.pDSParms->byCurrChannel mapping
3761 if( byCurrChannel > CB_MAX_CHANNEL_24G )
3763 if (sFrame.pDSParms) {
3764 if (byCurrChannel ==
3765 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
3768 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
3773 if (sFrame.pDSParms) {
3774 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
3776 byCurrChannel = sFrame.pDSParms->byCurrChannel;
3783 if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
3787 sERP.byERP = sFrame.pERP->byContext;
3788 sERP.bERPExist = true;
3790 sERP.bERPExist = false;
3794 // update or insert the bss
3795 pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
3796 sFrame.pHdr->sA3.abyAddr3,
3799 BSSbUpdateToBSSList((void *) pDevice,
3800 *sFrame.pqwTimestamp,
3801 *sFrame.pwBeaconInterval,
3807 sFrame.pExtSuppRates,
3814 sFrame.len - WLAN_HDR_ADDR3_LEN,
3815 /* payload of probresponse */
3816 sFrame.pHdr->sA4.abyAddr4,
3817 (void *) pRxPacket);
3819 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
3820 BSSbInsertToBSSList((void *) pDevice,
3821 sFrame.pHdr->sA3.abyAddr3,
3822 *sFrame.pqwTimestamp,
3823 *sFrame.pwBeaconInterval,
3828 sFrame.pExtSuppRates,
3834 sFrame.len - WLAN_HDR_ADDR3_LEN,
3835 sFrame.pHdr->sA4.abyAddr4, /* payload of beacon */
3836 (void *) pRxPacket);
3844 * Routine Description:(AP)or(Ad-hoc STA)
3845 * Handles probe request management frames.
3853 static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
3854 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
3856 WLAN_FR_PROBEREQ sFrame;
3858 struct vnt_tx_mgmt *pTxPacket;
3859 u8 byPHYType = BB_TYPE_11B;
3861 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
3862 // STA have to response this request.
3863 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
3864 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
3866 memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
3868 sFrame.len = pRxPacket->cbMPDULen;
3869 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
3870 vMgrDecodeProbeRequest(&sFrame);
3872 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%pM\n",
3873 sFrame.pHdr->sA3.abyAddr2);
3875 if (sFrame.pSSID->len != 0) {
3876 if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
3878 if (memcmp(sFrame.pSSID->abySSID,
3879 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
3880 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
3885 if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
3886 byPHYType = BB_TYPE_11G;
3889 // Probe response reply..
3890 pTxPacket = s_MgrMakeProbeResponse
3894 pMgmt->wCurrCapInfo,
3895 pMgmt->wCurrBeaconPeriod,
3896 pMgmt->uCurrChannel,
3898 sFrame.pHdr->sA3.abyAddr2,
3899 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
3900 (u8 *)pMgmt->abyCurrBSSID,
3901 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
3902 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
3905 if (pTxPacket != NULL ){
3906 /* send the frame */
3907 Status = csMgmt_xmit(pDevice, pTxPacket);
3908 if (Status != CMD_STATUS_PENDING) {
3909 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
3912 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
3922 * Routine Description:
3924 * Entry point for the reception and handling of 802.11 management
3925 * frames. Makes a determination of the frame type and then calls
3926 * the appropriate function.
3934 void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt,
3935 struct vnt_rx_mgmt *pRxPacket)
3937 int bInScan = false;
3939 NODE_STATE eNodeState = 0;
3942 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
3943 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
3944 eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
3947 switch( WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) ){
3949 case WLAN_FSTYPE_ASSOCREQ:
3951 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
3952 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
3953 (eNodeState < NODE_AUTH)) {
3954 // send deauth notification
3955 // reason = (6) class 2 received from nonauth sta
3956 vMgrDeAuthenBeginSta(pDevice,
3958 pRxPacket->p80211Header->sA3.abyAddr2,
3962 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
3965 s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
3969 case WLAN_FSTYPE_ASSOCRESP:
3971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
3972 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
3973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
3976 case WLAN_FSTYPE_REASSOCREQ:
3978 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
3980 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
3981 (eNodeState < NODE_AUTH)) {
3982 // send deauth notification
3983 // reason = (6) class 2 received from nonauth sta
3984 vMgrDeAuthenBeginSta(pDevice,
3986 pRxPacket->p80211Header->sA3.abyAddr2,
3990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
3993 s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
3996 case WLAN_FSTYPE_REASSOCRESP:
3998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
3999 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
4002 case WLAN_FSTYPE_PROBEREQ:
4004 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
4005 s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
4008 case WLAN_FSTYPE_PROBERESP:
4010 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
4012 s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
4015 case WLAN_FSTYPE_BEACON:
4017 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
4018 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
4021 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4024 case WLAN_FSTYPE_ATIM:
4026 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
4029 case WLAN_FSTYPE_DISASSOC:
4031 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
4032 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
4033 (eNodeState < NODE_AUTH)) {
4034 // send deauth notification
4035 // reason = (6) class 2 received from nonauth sta
4036 vMgrDeAuthenBeginSta(pDevice,
4038 pRxPacket->p80211Header->sA3.abyAddr2,
4042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
4044 s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
4047 case WLAN_FSTYPE_AUTHEN:
4049 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx authen\n");
4050 s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
4053 case WLAN_FSTYPE_DEAUTHEN:
4055 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
4056 s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
4060 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
4068 * Routine Description:
4071 * Prepare beacon to send
4074 * true if success; false if failed.
4077 int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
4078 struct vnt_manager *pMgmt)
4080 struct vnt_tx_mgmt *pTxPacket;
4082 // pDevice->bBeaconBufReady = false;
4083 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
4084 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4087 pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
4089 pTxPacket = s_MgrMakeBeacon
4093 pMgmt->wCurrCapInfo,
4094 pMgmt->wCurrBeaconPeriod,
4095 pMgmt->uCurrChannel,
4096 pMgmt->wCurrATIMWindow, //0,
4097 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4098 (u8 *)pMgmt->abyCurrBSSID,
4099 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4100 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
4103 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4104 (pMgmt->abyCurrBSSID[0] == 0))
4107 csBeacon_xmit(pDevice, pTxPacket);
4108 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
4115 * Routine Description:
4117 * Log a warning message based on the contents of the Status
4118 * Code field of an 802.11 management frame. Defines are
4119 * derived from 802.11-1997 SPEC.
4125 static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus)
4128 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
4129 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
4131 case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
4132 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
4134 case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
4135 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
4137 case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
4138 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
4140 case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
4141 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
4143 case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
4144 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
4146 case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
4147 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge failure.\n");
4149 case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
4150 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
4152 case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
4153 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
4155 case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
4156 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
4158 case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
4159 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
4161 case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
4162 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
4164 case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
4165 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
4168 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
4176 * Add BSSID in PMKID Candidate list.
4180 * hDeviceContext - device structure point
4181 * pbyBSSID - BSSID address for adding
4182 * wRSNCap - BSS's RSN capability
4186 * Return Value: none.
4190 int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID,
4191 PSRSNCapObject psRSNCapObj)
4193 PPMKID_CANDIDATE pCandidateList;
4196 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4198 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
4201 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
4204 // Update Old Candidate
4205 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
4206 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4207 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
4208 if ((psRSNCapObj->bRSNCapExist == true)
4209 && (psRSNCapObj->wRSNCap & BIT0)) {
4210 pCandidateList->Flags |=
4211 NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4213 pCandidateList->Flags &=
4214 ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4221 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
4222 if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
4223 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4225 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4227 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
4228 pDevice->gsPMKIDCandidate.NumCandidates++;
4229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4236 * Flush PMKID Candidate list.
4240 * hDeviceContext - device structure point
4244 * Return Value: none.
4248 void vFlush_PMKID_Candidate(struct vnt_private *pDevice)
4250 if (pDevice == NULL)
4253 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
4261 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
4266 u8 byMulticastCipher = KEY_CTL_INVALID;
4267 u8 byCipherMask = 0x00;
4270 if (pBSSNode == NULL)
4273 // check cap. of BSS
4274 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4275 (EncStatus == Ndis802_11Encryption1Enabled)) {
4276 // default is WEP only
4277 byMulticastCipher = KEY_CTL_WEP;
4280 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4281 (pBSSNode->bWPA2Valid == true) &&
4283 ((EncStatus == Ndis802_11Encryption3Enabled) ||
4284 (EncStatus == Ndis802_11Encryption2Enabled))) {
4286 // check Group Key Cipher
4287 if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
4288 (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
4289 byMulticastCipher = KEY_CTL_WEP;
4290 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
4291 byMulticastCipher = KEY_CTL_TKIP;
4292 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
4293 byMulticastCipher = KEY_CTL_CCMP;
4295 byMulticastCipher = KEY_CTL_INVALID;
4298 /* check Pairwise Key Cipher */
4299 for (i = 0; i < pBSSNode->wCSSPKCount; i++) {
4300 if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
4301 (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
4302 /* this should not happen as defined 802.11i */
4303 byCipherMask |= 0x01;
4304 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
4305 byCipherMask |= 0x02;
4306 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
4307 byCipherMask |= 0x04;
4308 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
4309 /* use group key only ignore all others */
4311 i = pBSSNode->wCSSPKCount;
4315 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4316 (pBSSNode->bWPAValid == true) &&
4317 ((EncStatus == Ndis802_11Encryption2Enabled) || (EncStatus == Ndis802_11Encryption3Enabled))) {
4319 // check Group Key Cipher
4320 if ((pBSSNode->byGKType == WPA_WEP40) ||
4321 (pBSSNode->byGKType == WPA_WEP104)) {
4322 byMulticastCipher = KEY_CTL_WEP;
4323 } else if (pBSSNode->byGKType == WPA_TKIP) {
4324 byMulticastCipher = KEY_CTL_TKIP;
4325 } else if (pBSSNode->byGKType == WPA_AESCCMP) {
4326 byMulticastCipher = KEY_CTL_CCMP;
4328 byMulticastCipher = KEY_CTL_INVALID;
4331 /* check Pairwise Key Cipher */
4332 for (i = 0; i < pBSSNode->wPKCount; i++) {
4333 if (pBSSNode->abyPKType[i] == WPA_TKIP) {
4334 byCipherMask |= 0x02;
4335 } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
4336 byCipherMask |= 0x04;
4337 } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
4338 /* use group key only ignore all others */
4340 i = pBSSNode->wPKCount;
4345 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%d, %d, %d, %d, EncStatus:%d\n",
4346 byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
4348 // mask our cap. with BSS
4349 if (EncStatus == Ndis802_11Encryption1Enabled) {
4351 // For supporting Cisco migration mode, don't care pairwise key cipher
4352 //if ((byMulticastCipher == KEY_CTL_WEP) &&
4353 // (byCipherMask == 0)) {
4354 if ((byMulticastCipher == KEY_CTL_WEP) &&
4355 (byCipherMask == 0)) {
4356 *pbyCCSGK = KEY_CTL_WEP;
4357 *pbyCCSPK = KEY_CTL_NONE;
4363 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
4364 if ((byMulticastCipher == KEY_CTL_TKIP) &&
4365 (byCipherMask == 0)) {
4366 *pbyCCSGK = KEY_CTL_TKIP;
4367 *pbyCCSPK = KEY_CTL_NONE;
4369 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4370 ((byCipherMask & 0x02) != 0)) {
4371 *pbyCCSGK = KEY_CTL_WEP;
4372 *pbyCCSPK = KEY_CTL_TKIP;
4374 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4375 ((byCipherMask & 0x02) != 0)) {
4376 *pbyCCSGK = KEY_CTL_TKIP;
4377 *pbyCCSPK = KEY_CTL_TKIP;
4382 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
4383 if ((byMulticastCipher == KEY_CTL_CCMP) &&
4384 (byCipherMask == 0)) {
4385 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
4387 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4388 ((byCipherMask & 0x04) != 0)) {
4389 *pbyCCSGK = KEY_CTL_WEP;
4390 *pbyCCSPK = KEY_CTL_CCMP;
4392 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4393 ((byCipherMask & 0x04) != 0)) {
4394 *pbyCCSGK = KEY_CTL_TKIP;
4395 *pbyCCSPK = KEY_CTL_CCMP;
4397 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
4398 ((byCipherMask & 0x04) != 0)) {
4399 *pbyCCSGK = KEY_CTL_CCMP;
4400 *pbyCCSPK = KEY_CTL_CCMP;