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