blob: 03629c562b1913a0ac42f579085b4e21a9591aee [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
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
Justin P. Mattocka0a1f612012-08-26 08:16:43 -070030 * vMgrObjectReset - Reset Management Object data structure
Forest Bond92b96792009-06-13 07:38:31 -040031 * 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
Masanari Iida93184692012-08-13 21:21:50 +090057 * s_vMgrFormatTIM- Assembler TIM field of beacon
Forest Bond92b96792009-06-13 07:38:31 -040058 * vMgrTimerInit- Initial 1-sec and command call back funtions
59 *
60 * Revision History:
61 *
62 */
63
Forest Bond92b96792009-06-13 07:38:31 -040064#include "tmacro.h"
Forest Bond92b96792009-06-13 07:38:31 -040065#include "desc.h"
Forest Bond92b96792009-06-13 07:38:31 -040066#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040067#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040068#include "80211hdr.h"
Forest Bond92b96792009-06-13 07:38:31 -040069#include "80211mgr.h"
Forest Bond92b96792009-06-13 07:38:31 -040070#include "wmgr.h"
Forest Bond92b96792009-06-13 07:38:31 -040071#include "wcmd.h"
Forest Bond92b96792009-06-13 07:38:31 -040072#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040073#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040074#include "power.h"
Forest Bond92b96792009-06-13 07:38:31 -040075#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040076#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040077#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040078#include "wpa.h"
Forest Bond92b96792009-06-13 07:38:31 -040079#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040080#include "iowpa.h"
Forest Bond92b96792009-06-13 07:38:31 -040081#include "control.h"
Forest Bond92b96792009-06-13 07:38:31 -040082#include "rndis.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070083
Forest Bond92b96792009-06-13 07:38:31 -040084static int msglevel =MSG_LEVEL_INFO;
85//static int msglevel =MSG_LEVEL_DEBUG;
86
Malcolm Priestley78f41c92012-12-10 22:03:56 +000087static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel);
Forest Bond92b96792009-06-13 07:38:31 -040088
Malcolm Priestley78f41c92012-12-10 22:03:56 +000089/* Association/diassociation functions */
90static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *,
91 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
92 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
93 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
Forest Bond92b96792009-06-13 07:38:31 -040094
Malcolm Priestley78f41c92012-12-10 22:03:56 +000095static void s_vMgrRxAssocRequest(struct vnt_private *,
96 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
97 u32 uNodeIndex);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestley78f41c92012-12-10 22:03:56 +000099static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *,
100 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
101 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
102 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
Forest Bond92b96792009-06-13 07:38:31 -0400103
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000104static void s_vMgrRxAssocResponse(struct vnt_private *,
105 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
106 int bReAssocType);
Forest Bond92b96792009-06-13 07:38:31 -0400107
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000108static void s_vMgrRxDisassociation(struct vnt_private *,
109 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000111/* Authentication/deauthen functions */
112static void s_vMgrRxAuthenSequence_1(struct vnt_private *,
113 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000115static void s_vMgrRxAuthenSequence_2(struct vnt_private *,
116 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000118static void s_vMgrRxAuthenSequence_3(struct vnt_private *,
119 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000121static void s_vMgrRxAuthenSequence_4(struct vnt_private *,
122 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000124static void s_vMgrRxAuthentication(struct vnt_private *,
125 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000127static void s_vMgrRxDeauthentication(struct vnt_private *,
128 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -0400129
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000130/* Scan functions
131* probe request/response functions */
Forest Bond92b96792009-06-13 07:38:31 -0400132
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000133static void s_vMgrRxProbeRequest(struct vnt_private *,
134 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -0400135
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000136static void s_vMgrRxProbeResponse(struct vnt_private *,
137 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000139/* beacon functions */
140static void s_vMgrRxBeacon(struct vnt_private *pDevice,
141 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
142 int bInScan);
Forest Bond92b96792009-06-13 07:38:31 -0400143
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000144static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM);
145
146static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
147 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
148 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
149 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
150 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
Forest Bond92b96792009-06-13 07:38:31 -0400151
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000152/* Association response */
153static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *,
154 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
155 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
156 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
Forest Bond92b96792009-06-13 07:38:31 -0400157
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000158/* ReAssociation response */
159static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *,
160 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
161 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
162 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
Forest Bond92b96792009-06-13 07:38:31 -0400163
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000164/* Probe response */
165static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *,
166 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
167 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
168 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
169 PWLAN_IE_SUPP_RATES pCurrSuppRates,
170 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType);
Forest Bond92b96792009-06-13 07:38:31 -0400171
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000172/* received status */
173static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus);
Forest Bond92b96792009-06-13 07:38:31 -0400174
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000175static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode,
176 PKnownBSS pCurr, PCMD_STATUS pStatus);
Forest Bond92b96792009-06-13 07:38:31 -0400177
Andres Moredfdcc422013-02-12 20:36:28 -0500178static bool
Forest Bond92b96792009-06-13 07:38:31 -0400179s_bCipherMatch (
Andres More592ccfe2010-04-17 12:07:42 -0300180 PKnownBSS pBSSNode,
181 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
Andres Moreb902fbf2013-02-25 20:32:51 -0500182 u8 * pbyCCSPK,
183 u8 * pbyCCSGK
Forest Bond92b96792009-06-13 07:38:31 -0400184 );
185
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000186static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr);
Forest Bond92b96792009-06-13 07:38:31 -0400187
Forest Bond92b96792009-06-13 07:38:31 -0400188/*+
189 *
190 * Routine Description:
191 * Allocates and initializes the Management object.
192 *
193 * Return Value:
194 * Ndis_staus.
195 *
196-*/
197
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000198void vMgrObjectInit(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400199{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000200 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
201 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400202
Forest Bond92b96792009-06-13 07:38:31 -0400203 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
204 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
205 pMgmt->uCurrChannel = pDevice->uChannel;
Andres More33d33e422010-05-19 23:50:00 -0300206 for (ii = 0; ii < WLAN_BSSID_LEN; ii++)
207 pMgmt->abyDesireBSSID[ii] = 0xFF;
208
Forest Bond92b96792009-06-13 07:38:31 -0400209 pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
210 //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
211 pMgmt->byCSSPK = KEY_CTL_NONE;
212 pMgmt->byCSSGK = KEY_CTL_NONE;
213 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
Andres Moree269fc22013-02-12 20:36:29 -0500214 BSSvClearBSSList((void *) pDevice, false);
Forest Bond92b96792009-06-13 07:38:31 -0400215
216 init_timer(&pMgmt->sTimerSecondCallback);
Andres Morecc856e62010-05-17 21:34:01 -0300217 pMgmt->sTimerSecondCallback.data = (unsigned long)pDevice;
Forest Bond92b96792009-06-13 07:38:31 -0400218 pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
219 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
220
Forest Bond92b96792009-06-13 07:38:31 -0400221 init_timer(&pDevice->sTimerTxData);
Andres Morecc856e62010-05-17 21:34:01 -0300222 pDevice->sTimerTxData.data = (unsigned long)pDevice;
Forest Bond92b96792009-06-13 07:38:31 -0400223 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
224 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
Andres Moree269fc22013-02-12 20:36:29 -0500225 pDevice->fTxDataInSleep = false;
226 pDevice->IsTxDataTrigger = false;
Forest Bond92b96792009-06-13 07:38:31 -0400227 pDevice->nTxDataTimeCout = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400228
229 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
230 pDevice->uCmdDequeueIdx = 0;
231 pDevice->uCmdEnqueueIdx = 0;
232 pDevice->eCommandState = WLAN_CMD_IDLE;
Andres Moree269fc22013-02-12 20:36:29 -0500233 pDevice->bCmdRunning = false;
234 pDevice->bCmdClear = false;
Forest Bond92b96792009-06-13 07:38:31 -0400235
236 return;
237}
238
Forest Bond92b96792009-06-13 07:38:31 -0400239/*+
240 *
241 * Routine Description:
242 * Start the station association procedure. Namely, send an
243 * association request frame to the AP.
244 *
245 * Return Value:
246 * None.
247 *
248-*/
249
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000250void vMgrAssocBeginSta(struct vnt_private *pDevice,
251 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -0400252{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000253 struct vnt_tx_mgmt *pTxPacket;
Forest Bond92b96792009-06-13 07:38:31 -0400254
Forest Bond92b96792009-06-13 07:38:31 -0400255 pMgmt->wCurrCapInfo = 0;
256 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
257 if (pDevice->bEncryptionEnable) {
258 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
259 }
260 // always allow receive short preamble
261 //if (pDevice->byPreambleType == 1) {
262 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
263 //}
264 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
265 if (pMgmt->wListenInterval == 0)
266 pMgmt->wListenInterval = 1; // at least one.
267
268 // ERP Phy (802.11g) should support short preamble.
269 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
270 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
Andres More4e9b5e22013-02-12 20:36:30 -0500271 if (pDevice->bShortSlotTime == true)
Forest Bond92b96792009-06-13 07:38:31 -0400272 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
273
274 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
275 if (pDevice->byPreambleType == 1) {
276 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
277 }
278 }
Andres More4e9b5e22013-02-12 20:36:30 -0500279 if (pMgmt->b11hEnable == true)
Forest Bond92b96792009-06-13 07:38:31 -0400280 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
281
282 // build an assocreq frame and send it
283 pTxPacket = s_MgrMakeAssocRequest
284 (
285 pDevice,
286 pMgmt,
287 pMgmt->abyCurrBSSID,
288 pMgmt->wCurrCapInfo,
289 pMgmt->wListenInterval,
290 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
291 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
292 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
293 );
294
295 if (pTxPacket != NULL ){
296 // send the frame
297 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
298 if (*pStatus == CMD_STATUS_PENDING) {
299 pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
300 *pStatus = CMD_STATUS_SUCCESS;
301 }
302 }
303 else
304 *pStatus = CMD_STATUS_RESOURCES;
305
306 return ;
307}
308
Forest Bond92b96792009-06-13 07:38:31 -0400309/*+
310 *
311 * Routine Description:
312 * Start the station re-association procedure.
313 *
314 * Return Value:
315 * None.
316 *
317-*/
318
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000319void vMgrReAssocBeginSta(struct vnt_private *pDevice,
320 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -0400321{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000322 struct vnt_tx_mgmt *pTxPacket;
Forest Bond92b96792009-06-13 07:38:31 -0400323
324 pMgmt->wCurrCapInfo = 0;
325 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
326 if (pDevice->bEncryptionEnable) {
327 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
328 }
329
330 //if (pDevice->byPreambleType == 1) {
331 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
332 //}
333 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
334
335 if (pMgmt->wListenInterval == 0)
336 pMgmt->wListenInterval = 1; // at least one.
337
Forest Bond92b96792009-06-13 07:38:31 -0400338 // ERP Phy (802.11g) should support short preamble.
339 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
340 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
Andres More4e9b5e22013-02-12 20:36:30 -0500341 if (pDevice->bShortSlotTime == true)
Forest Bond92b96792009-06-13 07:38:31 -0400342 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
343
344 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
345 if (pDevice->byPreambleType == 1) {
346 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
347 }
348 }
Andres More4e9b5e22013-02-12 20:36:30 -0500349 if (pMgmt->b11hEnable == true)
Forest Bond92b96792009-06-13 07:38:31 -0400350 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
351
Forest Bond92b96792009-06-13 07:38:31 -0400352 pTxPacket = s_MgrMakeReAssocRequest
353 (
354 pDevice,
355 pMgmt,
356 pMgmt->abyCurrBSSID,
357 pMgmt->wCurrCapInfo,
358 pMgmt->wListenInterval,
359 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
360 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
361 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
362 );
363
364 if (pTxPacket != NULL ){
365 // send the frame
366 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
367 if (*pStatus != CMD_STATUS_PENDING) {
368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
369 }
370 else {
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
372 }
373 }
374
Forest Bond92b96792009-06-13 07:38:31 -0400375 return ;
376}
377
378/*+
379 *
380 * Routine Description:
381 * Send an dis-association request frame to the AP.
382 *
383 * Return Value:
384 * None.
385 *
386-*/
387
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000388void vMgrDisassocBeginSta(struct vnt_private *pDevice,
389 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
390 PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -0400391{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000392 struct vnt_tx_mgmt *pTxPacket = NULL;
393 WLAN_FR_DISASSOC sFrame;
Forest Bond92b96792009-06-13 07:38:31 -0400394
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000395 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
396 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
397 + WLAN_DISASSOC_FR_MAXLEN);
398 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
399 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -0400400
401 // Setup the sFrame structure
Andres Moreb902fbf2013-02-25 20:32:51 -0500402 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400403 sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
404
405 // format fixed field frame structure
406 vMgrEncodeDisassociation(&sFrame);
407
408 // Setup the header
409 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
410 (
411 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
412 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
413 ));
414
415 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
416 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
417 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
418
419 // Set reason code
420 *(sFrame.pwReason) = cpu_to_le16(wReason);
421 pTxPacket->cbMPDULen = sFrame.len;
422 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
423
424 // send the frame
425 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
426 if (*pStatus == CMD_STATUS_PENDING) {
427 pMgmt->eCurrState = WMAC_STATE_IDLE;
428 *pStatus = CMD_STATUS_SUCCESS;
Joe Perches9fc86022011-04-10 14:31:32 -0700429 }
Forest Bond92b96792009-06-13 07:38:31 -0400430
431 return;
432}
433
Forest Bond92b96792009-06-13 07:38:31 -0400434/*+
435 *
436 * Routine Description:(AP function)
437 * Handle incoming station association request frames.
438 *
439 * Return Value:
440 * None.
441 *
442-*/
443
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000444static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
445 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
446 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -0400447{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000448 WLAN_FR_ASSOCREQ sFrame;
449 CMD_STATUS Status;
450 struct vnt_tx_mgmt *pTxPacket;
451 u16 wAssocStatus = 0;
452 u16 wAssocAID = 0;
453 u32 uRateLen = WLAN_RATES_MAXLEN;
454 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
455 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
Forest Bond92b96792009-06-13 07:38:31 -0400456
Forest Bond92b96792009-06-13 07:38:31 -0400457 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
458 return;
459 // node index not found
460 if (!uNodeIndex)
461 return;
462
463 //check if node is authenticated
464 //decode the frame
465 memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
466 memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
467 memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
468 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -0500469 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400470
471 vMgrDecodeAssocRequest(&sFrame);
472
473 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
474 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
475 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
476 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
477 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
Andres More4e9b5e22013-02-12 20:36:30 -0500478 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
Forest Bond92b96792009-06-13 07:38:31 -0400479 // Todo: check sta basic rate, if ap can't support, set status code
480 if (pDevice->byBBType == BB_TYPE_11B) {
481 uRateLen = WLAN_RATES_MAXLEN_11B;
482 }
483 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
484 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
485 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
486 uRateLen);
487 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
488 if (pDevice->byBBType == BB_TYPE_11G) {
489 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
490 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
491 uRateLen);
492 } else {
493 abyCurrExtSuppRates[1] = 0;
494 }
495
Andres More8611a292010-05-01 14:25:00 -0300496 RATEvParseMaxRate((void *)pDevice,
Forest Bond92b96792009-06-13 07:38:31 -0400497 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
498 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
Andres Moree269fc22013-02-12 20:36:29 -0500499 false, // do not change our basic rate
Forest Bond92b96792009-06-13 07:38:31 -0400500 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
501 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
502 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
503 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
504 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
505 );
506
507 // set max tx rate
508 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
509 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
510 // Todo: check sta preamble, if ap can't support, set status code
511 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
512 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
513 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
514 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
Andres More3eaca0d2013-02-25 20:32:52 -0500515 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
Forest Bond92b96792009-06-13 07:38:31 -0400516 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
Andres More3eaca0d2013-02-25 20:32:52 -0500517 wAssocAID = (u16)uNodeIndex;
Forest Bond92b96792009-06-13 07:38:31 -0400518 // check if ERP support
519 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
Andres More4e9b5e22013-02-12 20:36:30 -0500520 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
Forest Bond92b96792009-06-13 07:38:31 -0400521
522 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
523 // B only STA join
Andres More4e9b5e22013-02-12 20:36:30 -0500524 pDevice->bProtectMode = true;
525 pDevice->bNonERPPresent = true;
Forest Bond92b96792009-06-13 07:38:31 -0400526 }
Andres Moree269fc22013-02-12 20:36:29 -0500527 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500528 pDevice->bBarkerPreambleMd = true;
Forest Bond92b96792009-06-13 07:38:31 -0400529 }
530
531 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
532 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
533 sFrame.pHdr->sA3.abyAddr2[0],
534 sFrame.pHdr->sA3.abyAddr2[1],
535 sFrame.pHdr->sA3.abyAddr2[2],
536 sFrame.pHdr->sA3.abyAddr2[3],
537 sFrame.pHdr->sA3.abyAddr2[4],
538 sFrame.pHdr->sA3.abyAddr2[5]
539 ) ;
540 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
541 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
542 }
543
Forest Bond92b96792009-06-13 07:38:31 -0400544 // assoc response reply..
545 pTxPacket = s_MgrMakeAssocResponse
546 (
547 pDevice,
548 pMgmt,
549 pMgmt->wCurrCapInfo,
550 wAssocStatus,
551 wAssocAID,
552 sFrame.pHdr->sA3.abyAddr2,
553 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
554 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
555 );
556 if (pTxPacket != NULL ){
557
558 if (pDevice->bEnableHostapd) {
559 return;
560 }
561 /* send the frame */
562 Status = csMgmt_xmit(pDevice, pTxPacket);
563 if (Status != CMD_STATUS_PENDING) {
564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
565 }
566 else {
567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
568 }
569
570 }
571
572 return;
573}
574
Forest Bond92b96792009-06-13 07:38:31 -0400575/*+
576 *
577 * Description:(AP function)
578 * Handle incoming station re-association request frames.
579 *
580 * Parameters:
581 * In:
582 * pMgmt - Management Object structure
583 * pRxPacket - Received Packet
584 * Out:
585 * none
586 *
587 * Return Value: None.
588 *
589-*/
590
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000591static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
592 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
593 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -0400594{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000595 WLAN_FR_REASSOCREQ sFrame;
596 CMD_STATUS Status;
597 struct vnt_tx_mgmt *pTxPacket;
598 u16 wAssocStatus = 0;
599 u16 wAssocAID = 0;
600 u32 uRateLen = WLAN_RATES_MAXLEN;
601 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
602 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
Forest Bond92b96792009-06-13 07:38:31 -0400603
604 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
605 return;
606 // node index not found
607 if (!uNodeIndex)
608 return;
609 //check if node is authenticated
610 //decode the frame
611 memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
612 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -0500613 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400614 vMgrDecodeReassocRequest(&sFrame);
615
616 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
617 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
618 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
619 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
620 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
Andres More4e9b5e22013-02-12 20:36:30 -0500621 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
Forest Bond92b96792009-06-13 07:38:31 -0400622 // Todo: check sta basic rate, if ap can't support, set status code
623
624 if (pDevice->byBBType == BB_TYPE_11B) {
625 uRateLen = WLAN_RATES_MAXLEN_11B;
626 }
627
628 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
629 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
630 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
631 uRateLen);
632 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
633 if (pDevice->byBBType == BB_TYPE_11G) {
634 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
635 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
636 uRateLen);
637 } else {
638 abyCurrExtSuppRates[1] = 0;
639 }
640
Andres More8611a292010-05-01 14:25:00 -0300641 RATEvParseMaxRate((void *)pDevice,
Forest Bond92b96792009-06-13 07:38:31 -0400642 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
643 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
Andres Moree269fc22013-02-12 20:36:29 -0500644 false, // do not change our basic rate
Forest Bond92b96792009-06-13 07:38:31 -0400645 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
646 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
647 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
648 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
649 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
650 );
651
652 // set max tx rate
653 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
654 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
655 // Todo: check sta preamble, if ap can't support, set status code
656 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
657 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
658 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
659 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
Andres More3eaca0d2013-02-25 20:32:52 -0500660 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
Forest Bond92b96792009-06-13 07:38:31 -0400661 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
Andres More3eaca0d2013-02-25 20:32:52 -0500662 wAssocAID = (u16)uNodeIndex;
Forest Bond92b96792009-06-13 07:38:31 -0400663
664 // if suppurt ERP
665 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
Andres More4e9b5e22013-02-12 20:36:30 -0500666 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
Forest Bond92b96792009-06-13 07:38:31 -0400667
668 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
669 // B only STA join
Andres More4e9b5e22013-02-12 20:36:30 -0500670 pDevice->bProtectMode = true;
671 pDevice->bNonERPPresent = true;
Forest Bond92b96792009-06-13 07:38:31 -0400672 }
Andres Moree269fc22013-02-12 20:36:29 -0500673 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500674 pDevice->bBarkerPreambleMd = true;
Forest Bond92b96792009-06-13 07:38:31 -0400675 }
676
677 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
678 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
679 sFrame.pHdr->sA3.abyAddr2[0],
680 sFrame.pHdr->sA3.abyAddr2[1],
681 sFrame.pHdr->sA3.abyAddr2[2],
682 sFrame.pHdr->sA3.abyAddr2[3],
683 sFrame.pHdr->sA3.abyAddr2[4],
684 sFrame.pHdr->sA3.abyAddr2[5]
685 ) ;
686 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
687 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
688
689 }
690
Forest Bond92b96792009-06-13 07:38:31 -0400691 // assoc response reply..
692 pTxPacket = s_MgrMakeReAssocResponse
693 (
694 pDevice,
695 pMgmt,
696 pMgmt->wCurrCapInfo,
697 wAssocStatus,
698 wAssocAID,
699 sFrame.pHdr->sA3.abyAddr2,
700 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
701 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
702 );
703
704 if (pTxPacket != NULL ){
705 /* send the frame */
706 if (pDevice->bEnableHostapd) {
707 return;
708 }
709 Status = csMgmt_xmit(pDevice, pTxPacket);
710 if (Status != CMD_STATUS_PENDING) {
711 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
712 }
713 else {
714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
715 }
716 }
717 return;
718}
719
Forest Bond92b96792009-06-13 07:38:31 -0400720/*+
721 *
722 * Routine Description:
723 * Handle incoming association response frames.
724 *
725 * Return Value:
726 * None.
727 *
728-*/
729
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000730static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
731 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
732 int bReAssocType)
Forest Bond92b96792009-06-13 07:38:31 -0400733{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000734 WLAN_FR_ASSOCRESP sFrame;
735 PWLAN_IE_SSID pItemSSID;
736 u8 *pbyIEs;
Forest Bond92b96792009-06-13 07:38:31 -0400737
Forest Bond92b96792009-06-13 07:38:31 -0400738 if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
739 pMgmt->eCurrState == WMAC_STATE_ASSOC) {
740
741 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -0500742 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400743 // decode the frame
744 vMgrDecodeAssocResponse(&sFrame);
Andres More6e1b4e22010-05-04 20:40:11 -0300745 if ((sFrame.pwCapInfo == NULL)
746 || (sFrame.pwStatus == NULL)
747 || (sFrame.pwAid == NULL)
748 || (sFrame.pSuppRates == NULL)) {
Andres More6e1b4e22010-05-04 20:40:11 -0300749 return;
Joe Perches9fc86022011-04-10 14:31:32 -0700750 }
Forest Bond92b96792009-06-13 07:38:31 -0400751
752 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
753 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
754 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
755 pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
756
757 pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
758 pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
759 pbyIEs = pMgmt->sAssocInfo.abyIEs;
760 pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
761 memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
762
763 // save values and set current BSS state
764 if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
765 // set AID
766 pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
767 if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
768 {
769 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
Joe Perches9fc86022011-04-10 14:31:32 -0700770 }
Forest Bond92b96792009-06-13 07:38:31 -0400771 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
772 pMgmt->eCurrState = WMAC_STATE_ASSOC;
Andres More0cbd8d92010-05-06 20:34:29 -0300773 BSSvUpdateAPNode((void *) pDevice,
774 sFrame.pwCapInfo,
775 sFrame.pSuppRates,
776 sFrame.pExtSuppRates);
Forest Bond92b96792009-06-13 07:38:31 -0400777 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
778 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
Andres More4e9b5e22013-02-12 20:36:30 -0500779 pDevice->bLinkPass = true;
Forest Bond92b96792009-06-13 07:38:31 -0400780 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
Andres More465711b2010-08-03 20:25:50 -0300781
Andres More4e9b5e22013-02-12 20:36:30 -0500782 //if(pDevice->bWPASuppWextEnabled == true)
Forest Bond92b96792009-06-13 07:38:31 -0400783 {
Andres Moreb902fbf2013-02-25 20:32:51 -0500784 u8 buf[512];
Forest Bond92b96792009-06-13 07:38:31 -0400785 size_t len;
786 union iwreq_data wrqu;
787 int we_event;
788
789 memset(buf, 0, 512);
790
791 len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
792 if(len) {
793 memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
794 memset(&wrqu, 0, sizeof (wrqu));
795 wrqu.data.length = len;
796 we_event = IWEVASSOCREQIE;
797 PRINT_K("wireless_send_event--->IWEVASSOCREQIE\n");
798 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
799 }
800
801 memset(buf, 0, 512);
802 len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
803
804 if(len) {
805 memcpy(buf, pbyIEs, len);
806 memset(&wrqu, 0, sizeof (wrqu));
807 wrqu.data.length = len;
808 we_event = IWEVASSOCRESPIE;
809 PRINT_K("wireless_send_event--->IWEVASSOCRESPIE\n");
810 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
811 }
812
813 memset(&wrqu, 0, sizeof (wrqu));
814 memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
815 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
816 PRINT_K("wireless_send_event--->SIOCGIWAP(associated)\n");
817 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
818
819 }
Andres More465711b2010-08-03 20:25:50 -0300820
Forest Bond92b96792009-06-13 07:38:31 -0400821 }
822 else {
823 if (bReAssocType) {
824 pMgmt->eCurrState = WMAC_STATE_IDLE;
825 }
826 else {
827 // jump back to the auth state and indicate the error
828 pMgmt->eCurrState = WMAC_STATE_AUTH;
829 }
830 s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
831 }
832
833 }
834
Forest Bond92b96792009-06-13 07:38:31 -0400835//need clear flags related to Networkmanager
Andres Moree269fc22013-02-12 20:36:29 -0500836 pDevice->bwextstep0 = false;
837 pDevice->bwextstep1 = false;
838 pDevice->bwextstep2 = false;
839 pDevice->bwextstep3 = false;
840 pDevice->bWPASuppWextEnabled = false;
Forest Bond92b96792009-06-13 07:38:31 -0400841
Malcolm Priestley94488a72013-09-27 16:48:14 +0100842 if (pMgmt->eCurrState == WMAC_STATE_ASSOC)
843 schedule_delayed_work(&pDevice->run_command_work, 0);
Forest Bond92b96792009-06-13 07:38:31 -0400844
845 return;
846}
847
Forest Bond92b96792009-06-13 07:38:31 -0400848/*+
849 *
850 * Routine Description:
851 * Start the station authentication procedure. Namely, send an
852 * authentication frame to the AP.
853 *
854 * Return Value:
855 * None.
856 *
857-*/
858
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000859void vMgrAuthenBeginSta(struct vnt_private *pDevice,
860 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -0400861{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000862 WLAN_FR_AUTHEN sFrame;
863 struct vnt_tx_mgmt *pTxPacket =
864 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
Forest Bond92b96792009-06-13 07:38:31 -0400865
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000866 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
867 + WLAN_AUTHEN_FR_MAXLEN);
868 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
869 + sizeof(struct vnt_tx_mgmt));
Andres Moreb902fbf2013-02-25 20:32:51 -0500870 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400871 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
872 vMgrEncodeAuthen(&sFrame);
873 /* insert values */
874 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
875 (
876 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
877 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
878 ));
879 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
880 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
881 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
882 if (pMgmt->bShareKeyAlgorithm)
883 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
884 else
885 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
886
887 *(sFrame.pwAuthSequence) = cpu_to_le16(1);
888 /* Adjust the length fields */
889 pTxPacket->cbMPDULen = sFrame.len;
890 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
891
892 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
893 if (*pStatus == CMD_STATUS_PENDING){
894 pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
895 *pStatus = CMD_STATUS_SUCCESS;
896 }
897
898 return ;
899}
900
Forest Bond92b96792009-06-13 07:38:31 -0400901/*+
902 *
903 * Routine Description:
904 * Start the station(AP) deauthentication procedure. Namely, send an
905 * deauthentication frame to the AP or Sta.
906 *
907 * Return Value:
908 * None.
909 *
910-*/
911
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000912void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
913 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
914 PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -0400915{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000916 WLAN_FR_DEAUTHEN sFrame;
917 struct vnt_tx_mgmt *pTxPacket =
918 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
Forest Bond92b96792009-06-13 07:38:31 -0400919
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000920 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
921 + WLAN_DEAUTHEN_FR_MAXLEN);
922 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
923 + sizeof(struct vnt_tx_mgmt));
Andres Moreb902fbf2013-02-25 20:32:51 -0500924 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400925 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
926 vMgrEncodeDeauthen(&sFrame);
927 /* insert values */
928 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
929 (
930 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
931 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
932 ));
933
934 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
935 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
936 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
937
938 *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
939 /* Adjust the length fields */
940 pTxPacket->cbMPDULen = sFrame.len;
941 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
942
943 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
944 if (*pStatus == CMD_STATUS_PENDING){
945 *pStatus = CMD_STATUS_SUCCESS;
946 }
947
Forest Bond92b96792009-06-13 07:38:31 -0400948 return ;
949}
950
Forest Bond92b96792009-06-13 07:38:31 -0400951/*+
952 *
953 * Routine Description:
954 * Handle incoming authentication frames.
955 *
956 * Return Value:
957 * None.
958 *
959-*/
960
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000961static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
962 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
Forest Bond92b96792009-06-13 07:38:31 -0400963{
Malcolm Priestley78f41c92012-12-10 22:03:56 +0000964 WLAN_FR_AUTHEN sFrame;
Forest Bond92b96792009-06-13 07:38:31 -0400965
966 // we better be an AP or a STA in AUTHPENDING otherwise ignore
967 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
968 pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
969 return;
970 }
971
972 // decode the frame
973 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -0500974 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -0400975 vMgrDecodeAuthen(&sFrame);
976 switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
977 case 1:
978 //AP funciton
979 s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
980 break;
981 case 2:
982 s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
983 break;
984 case 3:
985 //AP funciton
986 s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
987 break;
988 case 4:
989 s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
990 break;
991 default:
992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
993 cpu_to_le16((*(sFrame.pwAuthSequence))));
994 break;
995 }
996 return;
997}
998
Forest Bond92b96792009-06-13 07:38:31 -0400999/*+
1000 *
1001 * Routine Description:
1002 * Handles incoming authen frames with sequence 1. Currently
1003 * assumes we're an AP. So far, no one appears to use authentication
1004 * in Ad-Hoc mode.
1005 *
1006 * Return Value:
1007 * None.
1008 *
1009-*/
1010
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001011static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
1012 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
Forest Bond92b96792009-06-13 07:38:31 -04001013{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001014 struct vnt_tx_mgmt *pTxPacket = NULL;
1015 u32 uNodeIndex;
1016 WLAN_FR_AUTHEN sFrame;
1017 PSKeyItem pTransmitKey;
Forest Bond92b96792009-06-13 07:38:31 -04001018
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001019 /* Insert a Node entry */
1020 if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2,
1021 &uNodeIndex)) {
1022 BSSvCreateOneNode(pDevice, &uNodeIndex);
1023 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr,
1024 pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1025 }
Forest Bond92b96792009-06-13 07:38:31 -04001026
1027 if (pMgmt->bShareKeyAlgorithm) {
1028 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
1029 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
1030 }
1031 else {
1032 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1033 }
1034
1035 // send auth reply
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001036 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1037 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1038 + WLAN_AUTHEN_FR_MAXLEN);
1039 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1040 + sizeof(struct vnt_tx_mgmt));
Andres Moreb902fbf2013-02-25 20:32:51 -05001041 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001042 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1043 // format buffer structure
1044 vMgrEncodeAuthen(&sFrame);
1045 // insert values
1046 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1047 (
1048 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1049 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1050 WLAN_SET_FC_ISWEP(0)
1051 ));
1052 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1053 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1054 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1055 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1056 *(sFrame.pwAuthSequence) = cpu_to_le16(2);
1057
1058 if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
1059 if (pMgmt->bShareKeyAlgorithm)
1060 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1061 else
1062 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1063 }
1064 else {
1065 if (pMgmt->bShareKeyAlgorithm)
1066 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1067 else
1068 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1069 }
1070
1071 if (pMgmt->bShareKeyAlgorithm &&
1072 (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
1073
1074 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1075 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1076 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1077 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1078 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1079 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001080 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001081 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1082 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1083 }
1084 memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
1085 }
1086
1087 /* Adjust the length fields */
1088 pTxPacket->cbMPDULen = sFrame.len;
1089 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1090 // send the frame
1091 if (pDevice->bEnableHostapd) {
1092 return;
1093 }
1094 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
1095 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
1097 }
1098 return;
1099}
1100
Forest Bond92b96792009-06-13 07:38:31 -04001101/*+
1102 *
1103 * Routine Description:
1104 * Handles incoming auth frames with sequence number 2. Currently
1105 * assumes we're a station.
1106 *
1107 *
1108 * Return Value:
1109 * None.
1110 *
1111-*/
1112
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001113static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
1114 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
Forest Bond92b96792009-06-13 07:38:31 -04001115{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001116 WLAN_FR_AUTHEN sFrame;
1117 struct vnt_tx_mgmt *pTxPacket = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001118
Forest Bond92b96792009-06-13 07:38:31 -04001119 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
1120 {
1121 case WLAN_AUTH_ALG_OPENSYSTEM:
1122 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1123 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
1124 pMgmt->eCurrState = WMAC_STATE_AUTH;
Malcolm Priestley94488a72013-09-27 16:48:14 +01001125 schedule_delayed_work(&pDevice->run_command_work, 0);
Forest Bond92b96792009-06-13 07:38:31 -04001126 }
1127 else {
1128 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
1129 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1130 pMgmt->eCurrState = WMAC_STATE_IDLE;
1131 }
Andres More0cbd8d92010-05-06 20:34:29 -03001132 if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
1133 /* spin_unlock_irq(&pDevice->lock);
1134 vCommandTimerWait((void *) pDevice, 0);
1135 spin_lock_irq(&pDevice->lock); */
Forest Bond92b96792009-06-13 07:38:31 -04001136 }
Forest Bond92b96792009-06-13 07:38:31 -04001137 break;
1138
1139 case WLAN_AUTH_ALG_SHAREDKEY:
1140
1141 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001142 pTxPacket = (struct vnt_tx_mgmt *)
1143 pMgmt->pbyMgmtPacketPool;
1144 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1145 + WLAN_AUTHEN_FR_MAXLEN);
1146 pTxPacket->p80211Header
1147 = (PUWLAN_80211HDR)((u8 *)pTxPacket
1148 + sizeof(struct vnt_tx_mgmt));
Andres Moreb902fbf2013-02-25 20:32:51 -05001149 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001150 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1151 // format buffer structure
1152 vMgrEncodeAuthen(&sFrame);
1153 // insert values
1154 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1155 (
1156 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1157 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1158 WLAN_SET_FC_ISWEP(1)
1159 ));
1160 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1161 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1162 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1163 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1164 *(sFrame.pwAuthSequence) = cpu_to_le16(3);
1165 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1166 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1167 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1168 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1169 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1170 memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
1171 // Adjust the length fields
1172 pTxPacket->cbMPDULen = sFrame.len;
1173 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1174 // send the frame
1175 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
1177 }
1178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
1179 }
1180 else {
1181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
1182 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
Andres More0cbd8d92010-05-06 20:34:29 -03001183 /* spin_unlock_irq(&pDevice->lock);
1184 vCommandTimerWait((void *) pDevice, 0);
1185 spin_lock_irq(&pDevice->lock); */
Forest Bond92b96792009-06-13 07:38:31 -04001186 }
1187 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1188 }
1189 break;
1190 default:
1191 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
1192 break;
1193 }
1194 return;
1195}
1196
Forest Bond92b96792009-06-13 07:38:31 -04001197/*+
1198 *
1199 * Routine Description:
1200 * Handles incoming authen frames with sequence 3. Currently
1201 * assumes we're an AP. This function assumes the frame has
1202 * already been successfully decrypted.
1203 *
1204 *
1205 * Return Value:
1206 * None.
1207 *
1208-*/
1209
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001210static void s_vMgrRxAuthenSequence_3(struct vnt_private *pDevice,
1211 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
Forest Bond92b96792009-06-13 07:38:31 -04001212{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001213 struct vnt_tx_mgmt *pTxPacket = NULL;
1214 u32 uStatusCode = 0 ;
1215 u32 uNodeIndex = 0;
1216 WLAN_FR_AUTHEN sFrame;
Forest Bond92b96792009-06-13 07:38:31 -04001217
1218 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1219 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1220 goto reply;
1221 }
1222 if (BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1223 if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
1224 uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
1225 goto reply;
1226 }
1227 if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
1228 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1229 goto reply;
1230 }
1231 }
1232 else {
1233 uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
1234 goto reply;
1235 }
1236
1237 if (uNodeIndex) {
1238 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1239 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
1240 }
1241 uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
1242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
1243
1244reply:
1245 // send auth reply
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001246 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1247 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1248 + WLAN_AUTHEN_FR_MAXLEN);
1249 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1250 + sizeof(struct vnt_tx_mgmt));
Andres Moreb902fbf2013-02-25 20:32:51 -05001251 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001252 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1253 // format buffer structure
1254 vMgrEncodeAuthen(&sFrame);
1255 /* insert values */
1256 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1257 (
1258 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1259 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1260 WLAN_SET_FC_ISWEP(0)
1261 ));
1262 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1263 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1264 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1265 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1266 *(sFrame.pwAuthSequence) = cpu_to_le16(4);
1267 *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
1268
1269 /* Adjust the length fields */
1270 pTxPacket->cbMPDULen = sFrame.len;
1271 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1272 // send the frame
1273 if (pDevice->bEnableHostapd) {
1274 return;
1275 }
1276 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
1278 }
1279 return;
1280
1281}
1282
Forest Bond92b96792009-06-13 07:38:31 -04001283/*+
1284 *
1285 * Routine Description:
1286 * Handles incoming authen frames with sequence 4
1287 *
1288 *
1289 * Return Value:
1290 * None.
1291 *
1292-*/
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001293static void s_vMgrRxAuthenSequence_4(struct vnt_private *pDevice,
1294 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
Forest Bond92b96792009-06-13 07:38:31 -04001295{
1296
1297 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1298 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
1299 pMgmt->eCurrState = WMAC_STATE_AUTH;
Malcolm Priestley94488a72013-09-27 16:48:14 +01001300 schedule_delayed_work(&pDevice->run_command_work, 0);
Forest Bond92b96792009-06-13 07:38:31 -04001301 }
1302 else{
1303 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
1304 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
1305 pMgmt->eCurrState = WMAC_STATE_IDLE;
1306 }
1307
1308 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
Andres More0cbd8d92010-05-06 20:34:29 -03001309 /* spin_unlock_irq(&pDevice->lock);
1310 vCommandTimerWait((void *) pDevice, 0);
1311 spin_lock_irq(&pDevice->lock); */
Forest Bond92b96792009-06-13 07:38:31 -04001312 }
Forest Bond92b96792009-06-13 07:38:31 -04001313}
1314
1315/*+
1316 *
1317 * Routine Description:
1318 * Handles incoming disassociation frames
1319 *
1320 *
1321 * Return Value:
1322 * None.
1323 *
1324-*/
1325
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001326static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
1327 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001328{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001329 WLAN_FR_DISASSOC sFrame;
1330 u32 uNodeIndex = 0;
1331 CMD_STATUS CmdStatus;
Forest Bond92b96792009-06-13 07:38:31 -04001332
1333 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1334 // if is acting an AP..
1335 // a STA is leaving this BSS..
1336 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05001337 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001338 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1339 BSSvRemoveOneNode(pDevice, uNodeIndex);
1340 }
1341 else {
1342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
1343 }
1344 }
1345 else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
1346 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05001347 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001348 vMgrDecodeDisassociation(&sFrame);
1349 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
1350
Andres Moree269fc22013-02-12 20:36:29 -05001351 pDevice->fWPA_Authened = false;
Forest Bond92b96792009-06-13 07:38:31 -04001352
1353 //TODO: do something let upper layer know or
1354 //try to send associate packet again because of inactivity timeout
1355 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
Andres Moree269fc22013-02-12 20:36:29 -05001356 pDevice->bLinkPass = false;
1357 pMgmt->sNodeDBTable[0].bActive = false;
Forest Bond92b96792009-06-13 07:38:31 -04001358 pDevice->byReAssocCount = 0;
1359 pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state!
1360 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001361 vMgrReAssocBeginSta(pDevice, pMgmt, &CmdStatus);
Forest Bond92b96792009-06-13 07:38:31 -04001362 if(CmdStatus == CMD_STATUS_PENDING) {
1363 pDevice->byReAssocCount ++;
1364 return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected!
1365 }
Joe Perches9fc86022011-04-10 14:31:32 -07001366 }
Forest Bond92b96792009-06-13 07:38:31 -04001367
Andres More4e9b5e22013-02-12 20:36:30 -05001368 // if(pDevice->bWPASuppWextEnabled == true)
Forest Bond92b96792009-06-13 07:38:31 -04001369 {
1370 union iwreq_data wrqu;
1371 memset(&wrqu, 0, sizeof (wrqu));
1372 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1373 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1374 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1375 }
Forest Bond92b96792009-06-13 07:38:31 -04001376 }
1377 /* else, ignore it */
1378
1379 return;
1380}
1381
Forest Bond92b96792009-06-13 07:38:31 -04001382/*+
1383 *
1384 * Routine Description:
1385 * Handles incoming deauthentication frames
1386 *
1387 *
1388 * Return Value:
1389 * None.
1390 *
1391-*/
1392
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001393static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
1394 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001395{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001396 WLAN_FR_DEAUTHEN sFrame;
1397 u32 uNodeIndex = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001398
Forest Bond92b96792009-06-13 07:38:31 -04001399 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1400 //Todo:
1401 // if is acting an AP..
1402 // a STA is leaving this BSS..
1403 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05001404 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001405 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1406 BSSvRemoveOneNode(pDevice, uNodeIndex);
1407 }
1408 else {
1409 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
1410 }
1411 }
1412 else {
1413 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
1414 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05001415 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001416 vMgrDecodeDeauthen(&sFrame);
Andres Moree269fc22013-02-12 20:36:29 -05001417 pDevice->fWPA_Authened = false;
Forest Bond92b96792009-06-13 07:38:31 -04001418 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
1419 // TODO: update BSS list for specific BSSID if pre-authentication case
Joe Perches83294192013-09-01 12:15:47 -07001420 if (ether_addr_equal(sFrame.pHdr->sA3.abyAddr3,
1421 pMgmt->abyCurrBSSID)) {
Forest Bond92b96792009-06-13 07:38:31 -04001422 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05001423 pMgmt->sNodeDBTable[0].bActive = false;
Forest Bond92b96792009-06-13 07:38:31 -04001424 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1425 pMgmt->eCurrState = WMAC_STATE_IDLE;
1426 netif_stop_queue(pDevice->dev);
Andres Moree269fc22013-02-12 20:36:29 -05001427 pDevice->bLinkPass = false;
Forest Bond92b96792009-06-13 07:38:31 -04001428 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1429 }
Joe Perches9fc86022011-04-10 14:31:32 -07001430 }
Forest Bond92b96792009-06-13 07:38:31 -04001431
Andres More4e9b5e22013-02-12 20:36:30 -05001432 // if(pDevice->bWPASuppWextEnabled == true)
Forest Bond92b96792009-06-13 07:38:31 -04001433 {
1434 union iwreq_data wrqu;
1435 memset(&wrqu, 0, sizeof (wrqu));
1436 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1437 PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
1438 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1439 }
Forest Bond92b96792009-06-13 07:38:31 -04001440
1441 }
1442 /* else, ignore it. TODO: IBSS authentication service
1443 would be implemented here */
1444 };
1445 return;
1446}
1447
Forest Bond92b96792009-06-13 07:38:31 -04001448/*+
1449 *
1450 * Routine Description:
1451 * check if current channel is match ZoneType.
1452 *for USA:1~11;
1453 * Japan:1~13;
1454 * Europe:1~13
1455 * Return Value:
1456 * True:exceed;
1457 * False:normal case
1458-*/
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001459static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel)
Forest Bond92b96792009-06-13 07:38:31 -04001460{
Andres Moree269fc22013-02-12 20:36:29 -05001461 int exceed = false;
Forest Bond92b96792009-06-13 07:38:31 -04001462
1463 switch(pDevice->byZoneType) {
1464 case 0x00: //USA:1~11
1465 if((byCurrChannel<1) ||(byCurrChannel>11))
Andres More4e9b5e22013-02-12 20:36:30 -05001466 exceed = true;
Forest Bond92b96792009-06-13 07:38:31 -04001467 break;
1468 case 0x01: //Japan:1~13
1469 case 0x02: //Europe:1~13
1470 if((byCurrChannel<1) ||(byCurrChannel>13))
Andres More4e9b5e22013-02-12 20:36:30 -05001471 exceed = true;
Forest Bond92b96792009-06-13 07:38:31 -04001472 break;
1473 default: //reserve for other zonetype
1474 break;
1475 }
1476
1477 return exceed;
1478}
1479
1480/*+
1481 *
1482 * Routine Description:
1483 * Handles and analysis incoming beacon frames.
1484 *
1485 *
1486 * Return Value:
1487 * None.
1488 *
1489-*/
1490
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001491static void s_vMgrRxBeacon(struct vnt_private *pDevice,
1492 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
1493 int bInScan)
Forest Bond92b96792009-06-13 07:38:31 -04001494{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001495 PKnownBSS pBSSList;
1496 WLAN_FR_BEACON sFrame;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001497 u64 qwTSFOffset;
Andres Moree269fc22013-02-12 20:36:29 -05001498 int bIsBSSIDEqual = false;
1499 int bIsSSIDEqual = false;
1500 int bTSFLargeDiff = false;
1501 int bTSFOffsetPostive = false;
1502 int bUpdateTSF = false;
1503 int bIsAPBeacon = false;
1504 int bIsChannelEqual = false;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001505 u32 uLocateByteIndex;
1506 u8 byTIMBitOn = 0;
1507 u16 wAIDNumber = 0;
1508 u32 uNodeIndex;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001509 u64 qwTimestamp, qwLocalTSF;
1510 u64 qwCurrTSF;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001511 u16 wStartIndex = 0;
1512 u16 wAIDIndex = 0;
1513 u8 byCurrChannel = pRxPacket->byRxChannel;
1514 ERPObject sERP;
1515 u32 uRateLen = WLAN_RATES_MAXLEN;
Andres Moree269fc22013-02-12 20:36:29 -05001516 int bChannelHit = false;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001517 u8 byOldPreambleType;
Forest Bond92b96792009-06-13 07:38:31 -04001518
Forest Bond92b96792009-06-13 07:38:31 -04001519 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
1520 return;
1521
1522 memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
1523 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05001524 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04001525
1526 // decode the beacon frame
1527 vMgrDecodeBeacon(&sFrame);
1528
Andres More6e1b4e22010-05-04 20:40:11 -03001529 if ((sFrame.pwBeaconInterval == NULL)
1530 || (sFrame.pwCapInfo == NULL)
1531 || (sFrame.pSSID == NULL)
1532 || (sFrame.pSuppRates == NULL)) {
Forest Bond92b96792009-06-13 07:38:31 -04001533
Andres More6e1b4e22010-05-04 20:40:11 -03001534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
1535 return;
Joe Perches9fc86022011-04-10 14:31:32 -07001536 }
Forest Bond92b96792009-06-13 07:38:31 -04001537
1538 if( byCurrChannel > CB_MAX_CHANNEL_24G )
1539 {
1540 if (sFrame.pDSParms != NULL) {
1541 if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
Andres More4e9b5e22013-02-12 20:36:30 -05001542 bChannelHit = true;
Forest Bond92b96792009-06-13 07:38:31 -04001543 byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
1544 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001545 bChannelHit = true;
Forest Bond92b96792009-06-13 07:38:31 -04001546 }
1547
1548 } else {
1549 if (sFrame.pDSParms != NULL) {
1550 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
Andres More4e9b5e22013-02-12 20:36:30 -05001551 bChannelHit = true;
Forest Bond92b96792009-06-13 07:38:31 -04001552 byCurrChannel = sFrame.pDSParms->byCurrChannel;
1553 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001554 bChannelHit = true;
Forest Bond92b96792009-06-13 07:38:31 -04001555 }
1556 }
1557
Andres More4e9b5e22013-02-12 20:36:30 -05001558if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
Forest Bond92b96792009-06-13 07:38:31 -04001559 return;
1560
1561 if (sFrame.pERP != NULL) {
1562 sERP.byERP = sFrame.pERP->byContext;
Andres More4e9b5e22013-02-12 20:36:30 -05001563 sERP.bERPExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001564
1565 } else {
Andres Moree269fc22013-02-12 20:36:29 -05001566 sERP.bERPExist = false;
Forest Bond92b96792009-06-13 07:38:31 -04001567 sERP.byERP = 0;
1568 }
1569
Andres More0cbd8d92010-05-06 20:34:29 -03001570 pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
1571 sFrame.pHdr->sA3.abyAddr3,
1572 sFrame.pSSID);
Forest Bond92b96792009-06-13 07:38:31 -04001573 if (pBSSList == NULL) {
1574 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
Andres More0cbd8d92010-05-06 20:34:29 -03001575 BSSbInsertToBSSList((void *) pDevice,
Forest Bond92b96792009-06-13 07:38:31 -04001576 sFrame.pHdr->sA3.abyAddr3,
1577 *sFrame.pqwTimestamp,
1578 *sFrame.pwBeaconInterval,
1579 *sFrame.pwCapInfo,
1580 byCurrChannel,
1581 sFrame.pSSID,
1582 sFrame.pSuppRates,
1583 sFrame.pExtSuppRates,
1584 &sERP,
1585 sFrame.pRSN,
1586 sFrame.pRSNWPA,
1587 sFrame.pIE_Country,
1588 sFrame.pIE_Quiet,
1589 sFrame.len - WLAN_HDR_ADDR3_LEN,
1590 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
Andres More0cbd8d92010-05-06 20:34:29 -03001591 (void *) pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -04001592 }
1593 else {
1594// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
Andres More0cbd8d92010-05-06 20:34:29 -03001595 BSSbUpdateToBSSList((void *) pDevice,
Forest Bond92b96792009-06-13 07:38:31 -04001596 *sFrame.pqwTimestamp,
1597 *sFrame.pwBeaconInterval,
1598 *sFrame.pwCapInfo,
1599 byCurrChannel,
1600 bChannelHit,
1601 sFrame.pSSID,
1602 sFrame.pSuppRates,
1603 sFrame.pExtSuppRates,
1604 &sERP,
1605 sFrame.pRSN,
1606 sFrame.pRSNWPA,
1607 sFrame.pIE_Country,
1608 sFrame.pIE_Quiet,
1609 pBSSList,
1610 sFrame.len - WLAN_HDR_ADDR3_LEN,
1611 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
Andres More0cbd8d92010-05-06 20:34:29 -03001612 (void *) pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -04001613
1614 }
1615
1616 if (bInScan) {
1617 return;
1618 }
1619
Andres Moreb902fbf2013-02-25 20:32:51 -05001620 if(byCurrChannel == (u8)pMgmt->uCurrChannel)
Andres More4e9b5e22013-02-12 20:36:30 -05001621 bIsChannelEqual = true;
Forest Bond92b96792009-06-13 07:38:31 -04001622
1623 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1624
1625 // if rx beacon without ERP field
1626 if (sERP.bERPExist) {
1627 if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
1628 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1629 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1630 }
1631 }
1632 else {
1633 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1634 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1635 }
1636
1637 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1638 if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
1639 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1640 if(!sERP.bERPExist)
1641 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1642 }
1643 }
1644
1645 // check if BSSID the same
1646 if (memcmp(sFrame.pHdr->sA3.abyAddr3,
1647 pMgmt->abyCurrBSSID,
1648 WLAN_BSSID_LEN) == 0) {
1649
Andres More4e9b5e22013-02-12 20:36:30 -05001650 bIsBSSIDEqual = true;
Forest Bond92b96792009-06-13 07:38:31 -04001651 pDevice->uCurrRSSI = pRxPacket->uRSSI;
1652 pDevice->byCurrSQ = pRxPacket->bySQ;
1653 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
1654 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1655 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
1656 }
1657 }
1658 // check if SSID the same
1659 if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
1660 if (memcmp(sFrame.pSSID->abySSID,
1661 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
1662 sFrame.pSSID->len
1663 ) == 0) {
Andres More4e9b5e22013-02-12 20:36:30 -05001664 bIsSSIDEqual = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001665 }
Forest Bond92b96792009-06-13 07:38:31 -04001666 }
1667
Andres More4e9b5e22013-02-12 20:36:30 -05001668 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
1669 (bIsBSSIDEqual == true) &&
1670 (bIsSSIDEqual == true) &&
Forest Bond92b96792009-06-13 07:38:31 -04001671 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1672 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1673 // add state check to prevent reconnect fail since we'll receive Beacon
1674
Andres More4e9b5e22013-02-12 20:36:30 -05001675 bIsAPBeacon = true;
Forest Bond92b96792009-06-13 07:38:31 -04001676 if (pBSSList != NULL) {
1677
1678 // Sync ERP field
Andres More4e9b5e22013-02-12 20:36:30 -05001679 if ((pBSSList->sERP.bERPExist == true) && (pDevice->byBBType == BB_TYPE_11G)) {
Forest Bond92b96792009-06-13 07:38:31 -04001680 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
1681 pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1682 if (pDevice->bProtectMode) {
1683 MACvEnableProtectMD(pDevice);
1684 } else {
1685 MACvDisableProtectMD(pDevice);
1686 }
1687 vUpdateIFS(pDevice);
1688 }
1689 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
1690 pDevice->bNonERPPresent = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1691 }
1692 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
1693 pDevice->bBarkerPreambleMd = (pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
1694 //BarkerPreambleMd has higher priority than shortPreamble bit in Cap
1695 if (pDevice->bBarkerPreambleMd) {
1696 MACvEnableBarkerPreambleMd(pDevice);
1697 } else {
1698 MACvDisableBarkerPreambleMd(pDevice);
1699 }
1700 }
1701 }
1702 // Sync Short Slot Time
1703 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) {
Andres Moredfdcc422013-02-12 20:36:28 -05001704 bool bShortSlotTime;
Forest Bond92b96792009-06-13 07:38:31 -04001705
1706 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo);
1707 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
1708 //Kyle check if it is OK to set G.
1709 if (pDevice->byBBType == BB_TYPE_11A) {
Andres More4e9b5e22013-02-12 20:36:30 -05001710 bShortSlotTime = true;
Forest Bond92b96792009-06-13 07:38:31 -04001711 }
1712 else if (pDevice->byBBType == BB_TYPE_11B) {
Andres Moree269fc22013-02-12 20:36:29 -05001713 bShortSlotTime = false;
Forest Bond92b96792009-06-13 07:38:31 -04001714 }
1715 if (bShortSlotTime != pDevice->bShortSlotTime) {
1716 pDevice->bShortSlotTime = bShortSlotTime;
1717 BBvSetShortSlotTime(pDevice);
1718 vUpdateIFS(pDevice);
1719 }
1720 }
1721
1722 //
Masanari Iida93184692012-08-13 21:21:50 +09001723 // Preamble may change dynamically
Forest Bond92b96792009-06-13 07:38:31 -04001724 //
1725 byOldPreambleType = pDevice->byPreambleType;
1726 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pBSSList->wCapInfo)) {
1727 pDevice->byPreambleType = pDevice->byShortPreamble;
1728 }
1729 else {
1730 pDevice->byPreambleType = 0;
1731 }
1732 if (pDevice->byPreambleType != byOldPreambleType)
Andres Moreb902fbf2013-02-25 20:32:51 -05001733 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
Forest Bond92b96792009-06-13 07:38:31 -04001734 //
Masanari Iida93184692012-08-13 21:21:50 +09001735 // Basic Rate Set may change dynamically
Forest Bond92b96792009-06-13 07:38:31 -04001736 //
1737 if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
1738 uRateLen = WLAN_RATES_MAXLEN_11B;
1739 }
1740 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
1741 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1742 uRateLen);
1743 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
1744 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1745 uRateLen);
Andres More8611a292010-05-01 14:25:00 -03001746 RATEvParseMaxRate((void *)pDevice,
Forest Bond92b96792009-06-13 07:38:31 -04001747 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1748 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
Andres More4e9b5e22013-02-12 20:36:30 -05001749 true,
Forest Bond92b96792009-06-13 07:38:31 -04001750 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
1751 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
1752 &(pMgmt->sNodeDBTable[0].wSuppRate),
1753 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
1754 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
1755 );
1756
1757 }
1758 }
1759
1760// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
1761 // check if CF field exisit
1762 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
1763 if (sFrame.pCFParms->wCFPDurRemaining > 0) {
1764 // TODO: deal with CFP period to set NAV
Joe Perches9fc86022011-04-10 14:31:32 -07001765 }
1766 }
Forest Bond92b96792009-06-13 07:38:31 -04001767
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001768 qwTimestamp = cpu_to_le64(*sFrame.pqwTimestamp);
1769 qwLocalTSF = pRxPacket->qwLocalTSF;
Forest Bond92b96792009-06-13 07:38:31 -04001770
1771 // check if beacon TSF larger or small than our local TSF
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001772 if (qwTimestamp >= qwLocalTSF)
Andres More4e9b5e22013-02-12 20:36:30 -05001773 bTSFOffsetPostive = true;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001774 else
Andres Moree269fc22013-02-12 20:36:29 -05001775 bTSFOffsetPostive = false;
Forest Bond92b96792009-06-13 07:38:31 -04001776
1777 if (bTSFOffsetPostive) {
1778 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
1779 }
1780 else {
1781 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
1782 }
1783
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001784 if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
Andres More4e9b5e22013-02-12 20:36:30 -05001785 bTSFLargeDiff = true;
Forest Bond92b96792009-06-13 07:38:31 -04001786
Forest Bond92b96792009-06-13 07:38:31 -04001787 // if infra mode
Andres More4e9b5e22013-02-12 20:36:30 -05001788 if (bIsAPBeacon == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001789
1790 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
1791 if (bTSFLargeDiff)
Andres More4e9b5e22013-02-12 20:36:30 -05001792 bUpdateTSF = true;
Forest Bond92b96792009-06-13 07:38:31 -04001793
Andres More4e9b5e22013-02-12 20:36:30 -05001794 if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM)) {
Forest Bond92b96792009-06-13 07:38:31 -04001795
Andres More6e1b4e22010-05-04 20:40:11 -03001796 /* deal with DTIM, analysis TIM */
Andres More4e9b5e22013-02-12 20:36:30 -05001797 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
Forest Bond92b96792009-06-13 07:38:31 -04001798 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
1799 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
1800 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
1801
1802 // check if AID in TIM field bit on
1803 // wStartIndex = N1
1804 wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
1805 // AIDIndex = N2
1806 wAIDIndex = (wAIDNumber >> 3);
1807 if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
1808 uLocateByteIndex = wAIDIndex - wStartIndex;
1809 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
1810 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
1811 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
Andres More4e9b5e22013-02-12 20:36:30 -05001812 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
Forest Bond92b96792009-06-13 07:38:31 -04001813 }
1814 else {
Andres Moree269fc22013-02-12 20:36:29 -05001815 pMgmt->bInTIM = false;
Forest Bond92b96792009-06-13 07:38:31 -04001816 };
1817 }
1818 else {
Andres Moree269fc22013-02-12 20:36:29 -05001819 pMgmt->bInTIM = false;
Forest Bond92b96792009-06-13 07:38:31 -04001820 };
1821
1822 if (pMgmt->bInTIM ||
1823 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
Andres More4e9b5e22013-02-12 20:36:30 -05001824 pMgmt->bInTIMWake = true;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001825 /* send out ps-poll packet */
1826 if (pMgmt->bInTIM)
1827 PSvSendPSPOLL(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001828
1829 }
1830 else {
Andres Moree269fc22013-02-12 20:36:29 -05001831 pMgmt->bInTIMWake = false;
Forest Bond92b96792009-06-13 07:38:31 -04001832 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
Andres Moree269fc22013-02-12 20:36:29 -05001833 if (pDevice->bPWBitOn == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001834 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
1835 if (PSbSendNullPacket(pDevice))
Andres More4e9b5e22013-02-12 20:36:30 -05001836 pDevice->bPWBitOn = true;
Forest Bond92b96792009-06-13 07:38:31 -04001837 }
Andres Moree269fc22013-02-12 20:36:29 -05001838 if(PSbConsiderPowerDown(pDevice, false, false)) {
Forest Bond92b96792009-06-13 07:38:31 -04001839 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
Joe Perches9fc86022011-04-10 14:31:32 -07001840 }
Forest Bond92b96792009-06-13 07:38:31 -04001841 }
1842
1843 }
1844
1845 }
1846 // if adhoc mode
1847 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
1848 if (bIsBSSIDEqual) {
1849 // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
1850 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
1851 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1852
1853 // adhoc mode:TSF updated only when beacon larger then local TSF
1854 if (bTSFLargeDiff && bTSFOffsetPostive &&
1855 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
Andres More4e9b5e22013-02-12 20:36:30 -05001856 bUpdateTSF = true;
Forest Bond92b96792009-06-13 07:38:31 -04001857
1858 // During dpc, already in spinlocked.
1859 if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
1860
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001861 // Update the STA, (Technically the Beacons of all the IBSS nodes
Forest Bond92b96792009-06-13 07:38:31 -04001862 // should be identical, but that's not happening in practice.
1863 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1864 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1865 WLAN_RATES_MAXLEN_11B);
Andres More8611a292010-05-01 14:25:00 -03001866 RATEvParseMaxRate((void *)pDevice,
Forest Bond92b96792009-06-13 07:38:31 -04001867 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1868 NULL,
Andres More4e9b5e22013-02-12 20:36:30 -05001869 true,
Forest Bond92b96792009-06-13 07:38:31 -04001870 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
1871 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
1872 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
1873 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
1874 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
1875 );
1876 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
1877 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
1878 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
1879 }
1880 else {
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001881 /* Todo, initial Node content */
1882 BSSvCreateOneNode(pDevice, &uNodeIndex);
Forest Bond92b96792009-06-13 07:38:31 -04001883
1884 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1885 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1886 WLAN_RATES_MAXLEN_11B);
Andres More8611a292010-05-01 14:25:00 -03001887 RATEvParseMaxRate((void *)pDevice,
Forest Bond92b96792009-06-13 07:38:31 -04001888 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1889 NULL,
Andres More4e9b5e22013-02-12 20:36:30 -05001890 true,
Forest Bond92b96792009-06-13 07:38:31 -04001891 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
1892 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
1893 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
1894 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
1895 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
1896 );
1897
1898 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1899 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
1900 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
1901/*
1902 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
1903 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
Andres More4e9b5e22013-02-12 20:36:30 -05001904 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001905*/
1906 }
1907
1908 // if other stations jointed, indicate connect to upper layer..
1909 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
1910 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
1911 pMgmt->eCurrState = WMAC_STATE_JOINTED;
Andres More4e9b5e22013-02-12 20:36:30 -05001912 pDevice->bLinkPass = true;
Forest Bond92b96792009-06-13 07:38:31 -04001913 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
1914 if (netif_queue_stopped(pDevice->dev)){
1915 netif_wake_queue(pDevice->dev);
1916 }
Andres More4e9b5e22013-02-12 20:36:30 -05001917 pMgmt->sNodeDBTable[0].bActive = true;
Forest Bond92b96792009-06-13 07:38:31 -04001918 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1919
Joe Perches9fc86022011-04-10 14:31:32 -07001920 }
Forest Bond92b96792009-06-13 07:38:31 -04001921 }
1922 else if (bIsSSIDEqual) {
1923
1924 // See other adhoc sta with the same SSID but BSSID is different.
1925 // adpot this vars only when TSF larger then us.
1926 if (bTSFLargeDiff && bTSFOffsetPostive) {
1927 // we don't support ATIM under adhoc mode
1928 // if ( sFrame.pIBSSParms->wATIMWindow == 0) {
1929 // adpot this vars
1930 // TODO: check sFrame cap if privacy on, and support rate syn
1931 memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
1932 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1933 pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
1934 pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
1935 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1936 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1937 WLAN_RATES_MAXLEN_11B);
1938 // set HW beacon interval and re-synchronizing....
1939 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
1940
1941 MACvWriteBeaconInterval(pDevice, pMgmt->wCurrBeaconPeriod);
1942 CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
1943 CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
1944
1945 // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
1946 MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
1947
1948 byOldPreambleType = pDevice->byPreambleType;
1949 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo)) {
1950 pDevice->byPreambleType = pDevice->byShortPreamble;
1951 }
1952 else {
1953 pDevice->byPreambleType = 0;
1954 }
1955 if (pDevice->byPreambleType != byOldPreambleType)
Andres Moreb902fbf2013-02-25 20:32:51 -05001956 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
Forest Bond92b96792009-06-13 07:38:31 -04001957
Forest Bond92b96792009-06-13 07:38:31 -04001958 // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
1959 // set highest basic rate
1960 // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
1961 // Prepare beacon frame
Andres More0cbd8d92010-05-06 20:34:29 -03001962 bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
Forest Bond92b96792009-06-13 07:38:31 -04001963 // }
Joe Perches9fc86022011-04-10 14:31:32 -07001964 }
Forest Bond92b96792009-06-13 07:38:31 -04001965 }
Joe Perches9fc86022011-04-10 14:31:32 -07001966 }
Forest Bond92b96792009-06-13 07:38:31 -04001967 // endian issue ???
1968 // Update TSF
1969 if (bUpdateTSF) {
1970 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
1971 CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp , pRxPacket->qwLocalTSF);
1972 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
1973 CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
1974 }
1975
1976 return;
1977}
1978
Forest Bond92b96792009-06-13 07:38:31 -04001979/*+
1980 *
1981 * Routine Description:
1982 * Instructs the hw to create a bss using the supplied
1983 * attributes. Note that this implementation only supports Ad-Hoc
1984 * BSS creation.
1985 *
1986 *
1987 * Return Value:
1988 * CMD_STATUS
1989 *
1990-*/
Andres More0cbd8d92010-05-06 20:34:29 -03001991
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001992void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -04001993{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00001994 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1995 u16 wMaxBasicRate;
1996 u16 wMaxSuppRate;
1997 u8 byTopCCKBasicRate;
1998 u8 byTopOFDMBasicRate;
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00001999 u64 qwCurrTSF = 0;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002000 int ii;
2001 u8 abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C,
2002 0x12, 0x18, 0x60};
2003 u8 abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
2004 u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2005 u16 wSuppRate;
Forest Bond92b96792009-06-13 07:38:31 -04002006
Forest Bond92b96792009-06-13 07:38:31 -04002007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
2008
2009 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2010 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
2011 (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
2012 (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
2013 // encryption mode error
2014 *pStatus = CMD_STATUS_FAILURE;
2015 return;
2016 }
2017 }
2018
2019 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2020 pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
2021
2022 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2023 pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
2024 } else {
2025 if (pDevice->byBBType == BB_TYPE_11G)
2026 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2027 if (pDevice->byBBType == BB_TYPE_11B)
2028 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2029 if (pDevice->byBBType == BB_TYPE_11A)
2030 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2031 }
2032
2033 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
2034 pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
2035 pMgmt->abyCurrExtSuppRates[1] = 0;
2036 for (ii = 0; ii < 4; ii++)
2037 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2038 } else {
2039 pMgmt->abyCurrSuppRates[1] = 8;
2040 pMgmt->abyCurrExtSuppRates[1] = 0;
2041 for (ii = 0; ii < 8; ii++)
2042 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2043 }
2044
Forest Bond92b96792009-06-13 07:38:31 -04002045 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2046 pMgmt->abyCurrSuppRates[1] = 8;
2047 pMgmt->abyCurrExtSuppRates[1] = 4;
2048 for (ii = 0; ii < 4; ii++)
2049 pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
2050 for (ii = 4; ii < 8; ii++)
2051 pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
2052 for (ii = 0; ii < 4; ii++)
2053 pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
2054 }
2055
Forest Bond92b96792009-06-13 07:38:31 -04002056 // Disable Protect Mode
2057 pDevice->bProtectMode = 0;
2058 MACvDisableProtectMD(pDevice);
2059
2060 pDevice->bBarkerPreambleMd = 0;
2061 MACvDisableBarkerPreambleMd(pDevice);
2062
2063 // Kyle Test 2003.11.04
2064
2065 // set HW beacon interval
2066 if (pMgmt->wIBSSBeaconPeriod == 0)
2067 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
2068 MACvWriteBeaconInterval(pDevice, pMgmt->wIBSSBeaconPeriod);
2069
2070 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
2071 // clear TSF counter
2072 CARDbClearCurrentTSF(pDevice);
2073
2074 // enable TSF counter
2075 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTREN);
2076 // set Next TBTT
2077 CARDvSetFirstNextTBTT(pDevice, pMgmt->wIBSSBeaconPeriod);
2078
2079 pMgmt->uIBSSChannel = pDevice->uChannel;
2080
2081 if (pMgmt->uIBSSChannel == 0)
2082 pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
2083
2084 // set channel and clear NAV
2085 CARDbSetMediaChannel(pDevice, pMgmt->uIBSSChannel);
2086 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2087
2088 pDevice->byPreambleType = pDevice->byShortPreamble;
2089
2090 // set basic rate
2091
Andres More8611a292010-05-01 14:25:00 -03002092 RATEvParseMaxRate((void *)pDevice,
2093 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
Andres More4e9b5e22013-02-12 20:36:30 -05002094 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
Forest Bond92b96792009-06-13 07:38:31 -04002095 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2096 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2097
Forest Bond92b96792009-06-13 07:38:31 -04002098 if (pDevice->byBBType == BB_TYPE_11A) {
Andres More4e9b5e22013-02-12 20:36:30 -05002099 pDevice->bShortSlotTime = true;
Forest Bond92b96792009-06-13 07:38:31 -04002100 } else {
Andres Moree269fc22013-02-12 20:36:29 -05002101 pDevice->bShortSlotTime = false;
Forest Bond92b96792009-06-13 07:38:31 -04002102 }
2103 BBvSetShortSlotTime(pDevice);
2104 // vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called
2105 // after setting ShortSlotTime.
2106 // CARDvSetBSSMode call vUpdateIFS()
2107 CARDvSetBSSMode(pDevice);
2108
2109 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2110 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_AP);
2111 pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
2112 }
2113
2114 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2115 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2116 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2117 }
2118
2119 // Adopt pre-configured IBSS vars to current vars
2120 pMgmt->eCurrState = WMAC_STATE_STARTED;
2121 pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
2122 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2123 pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
2124 pDevice->uCurrRSSI = 0;
2125 pDevice->byCurrSQ = 0;
2126
Forest Bond92b96792009-06-13 07:38:31 -04002127 memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
2128 ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04002129
2130 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2131 memcpy(pMgmt->abyCurrSSID,
2132 pMgmt->abyDesireSSID,
2133 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
2134 );
2135
2136 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2137 // AP mode BSSID = MAC addr
2138 memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
Andy Shevchenkod6a32aa2011-07-26 10:35:31 +03002139 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:"
2140 "%pM\n", pMgmt->abyCurrBSSID);
Forest Bond92b96792009-06-13 07:38:31 -04002141 }
2142
2143 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2144
2145 // BSSID selected must be randomized as spec 11.1.3
Malcolm Priestley7c65fa22012-11-28 21:11:02 +00002146 pMgmt->abyCurrBSSID[5] = (u8)(qwCurrTSF & 0x000000ff);
2147 pMgmt->abyCurrBSSID[4] = (u8)((qwCurrTSF & 0x0000ff00) >> 8);
2148 pMgmt->abyCurrBSSID[3] = (u8)((qwCurrTSF & 0x00ff0000) >> 16);
2149 pMgmt->abyCurrBSSID[2] = (u8)((qwCurrTSF & 0x00000ff0) >> 4);
2150 pMgmt->abyCurrBSSID[1] = (u8)((qwCurrTSF & 0x000ff000) >> 12);
2151 pMgmt->abyCurrBSSID[0] = (u8)((qwCurrTSF & 0x0ff00000) >> 20);
Forest Bond92b96792009-06-13 07:38:31 -04002152 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2153 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2154 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
2155 pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
2156 pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
2157 pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
2158 pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
2159 pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
2160
Andy Shevchenkod6a32aa2011-07-26 10:35:31 +03002161 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:"
2162 "%pM\n", pMgmt->abyCurrBSSID);
Forest Bond92b96792009-06-13 07:38:31 -04002163 }
2164
2165 // set BSSID filter
2166 MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
2167 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
2168
2169 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2170 pDevice->byRxMode |= RCR_BSSID;
Andres More4e9b5e22013-02-12 20:36:30 -05002171 pMgmt->bCurrBSSIDFilterOn = true;
Forest Bond92b96792009-06-13 07:38:31 -04002172
2173 // Set Capability Info
2174 pMgmt->wCurrCapInfo = 0;
2175
2176 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2177 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
2178 pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
2179 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2180 pDevice->eOPMode = OP_MODE_AP;
2181 }
2182
2183 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2184 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
2185 pDevice->eOPMode = OP_MODE_ADHOC;
2186 }
2187
2188 if (pDevice->bEncryptionEnable) {
2189 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
2190 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2191 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2192 pMgmt->byCSSPK = KEY_CTL_CCMP;
2193 pMgmt->byCSSGK = KEY_CTL_CCMP;
2194 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2195 pMgmt->byCSSPK = KEY_CTL_TKIP;
2196 pMgmt->byCSSGK = KEY_CTL_TKIP;
2197 } else {
2198 pMgmt->byCSSPK = KEY_CTL_NONE;
2199 pMgmt->byCSSGK = KEY_CTL_WEP;
2200 }
2201 } else {
2202 pMgmt->byCSSPK = KEY_CTL_WEP;
2203 pMgmt->byCSSGK = KEY_CTL_WEP;
2204 }
Joe Perches9fc86022011-04-10 14:31:32 -07002205 }
Forest Bond92b96792009-06-13 07:38:31 -04002206
2207 pMgmt->byERPContext = 0;
2208
2209 if (pDevice->byPreambleType == 1) {
2210 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
2211 } else {
2212 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
2213 }
2214
2215 pMgmt->eCurrState = WMAC_STATE_STARTED;
2216 // Prepare beacon to send
Andres More0cbd8d92010-05-06 20:34:29 -03002217 if (bMgrPrepareBeaconToSend((void *) pDevice, pMgmt))
2218 *pStatus = CMD_STATUS_SUCCESS;
2219
2220 return;
Forest Bond92b96792009-06-13 07:38:31 -04002221}
2222
Forest Bond92b96792009-06-13 07:38:31 -04002223/*+
2224 *
2225 * Routine Description:
2226 * Instructs wmac to join a bss using the supplied attributes.
2227 * The arguments may the BSSID or SSID and the rest of the
2228 * attributes are obtained from the scan result of known bss list.
2229 *
2230 *
2231 * Return Value:
2232 * None.
2233 *
2234-*/
2235
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002236void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -04002237{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002238 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2239 PKnownBSS pCurr = NULL;
2240 int ii, uu;
2241 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2242 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2243 PWLAN_IE_SSID pItemSSID;
2244 u32 uRateLen = WLAN_RATES_MAXLEN;
2245 u16 wMaxBasicRate = RATE_1M;
2246 u16 wMaxSuppRate = RATE_1M;
2247 u16 wSuppRate;
2248 u8 byTopCCKBasicRate = RATE_1M;
2249 u8 byTopOFDMBasicRate = RATE_1M;
Andres Moree269fc22013-02-12 20:36:29 -05002250 u8 bShortSlotTime = false;
Forest Bond92b96792009-06-13 07:38:31 -04002251
Forest Bond92b96792009-06-13 07:38:31 -04002252 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
Andres More4e9b5e22013-02-12 20:36:30 -05002253 if (pMgmt->sBSSList[ii].bActive == true)
Forest Bond92b96792009-06-13 07:38:31 -04002254 break;
2255 }
2256
2257 if (ii == MAX_BSS_NUM) {
2258 *pStatus = CMD_STATUS_RESOURCES;
2259 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
2260 return;
Joe Perches9fc86022011-04-10 14:31:32 -07002261 }
Forest Bond92b96792009-06-13 07:38:31 -04002262
2263 // memset(pMgmt->abyDesireBSSID, 0, WLAN_BSSID_LEN);
2264 // Search known BSS list for prefer BSSID or SSID
2265
2266 pCurr = BSSpSearchBSSList(pDevice,
2267 pMgmt->abyDesireBSSID,
2268 pMgmt->abyDesireSSID,
2269 pDevice->eConfigPHYMode
2270 );
2271
2272 if (pCurr == NULL){
2273 *pStatus = CMD_STATUS_RESOURCES;
2274 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
2275 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
2276 return;
Joe Perches9fc86022011-04-10 14:31:32 -07002277 }
Forest Bond92b96792009-06-13 07:38:31 -04002278
2279 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
2280
2281 if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
2282
Andres Morebd2bc4c2010-08-02 23:35:57 -03002283 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
2284 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2285 /*
Forest Bond92b96792009-06-13 07:38:31 -04002286 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
Andres Moree269fc22013-02-12 20:36:29 -05002287 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002288 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2289 // encryption mode error
2290 pMgmt->eCurrState = WMAC_STATE_IDLE;
2291 return;
2292 }
2293 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
Andres Moree269fc22013-02-12 20:36:29 -05002294 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2296 // encryption mode error
2297 pMgmt->eCurrState = WMAC_STATE_IDLE;
2298 return;
2299 }
2300 }
2301*/
2302 }
2303
Andres More4e9b5e22013-02-12 20:36:30 -05002304 //if(pDevice->bWPASuppWextEnabled == true)
Forest Bond92b96792009-06-13 07:38:31 -04002305 Encyption_Rebuild(pDevice, pCurr);
Forest Bond92b96792009-06-13 07:38:31 -04002306
2307 // Infrastructure BSS
2308 s_vMgrSynchBSS(pDevice,
2309 WMAC_MODE_ESS_STA,
2310 pCurr,
2311 pStatus
2312 );
2313
2314 if (*pStatus == CMD_STATUS_SUCCESS){
2315
2316 // Adopt this BSS state vars in Mgmt Object
2317 pMgmt->uCurrChannel = pCurr->uChannel;
2318
2319 memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2320 memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2321
2322 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2323 uRateLen = WLAN_RATES_MAXLEN_11B;
2324 }
2325
2326 pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
2327 pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
2328
2329 // Parse Support Rate IE
2330 pItemRates->byElementID = WLAN_EID_SUPP_RATES;
2331 pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2332 pItemRates,
2333 uRateLen);
2334
2335 // Parse Extension Support Rate IE
2336 pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
2337 pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
2338 pItemExtRates,
2339 uRateLen);
2340 // Stuffing Rate IE
2341 if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
Andres Morecc856e62010-05-17 21:34:01 -03002342 for (ii = 0; ii < (unsigned int) (8 - pItemRates->len); ) {
2343 pItemRates->abyRates[pItemRates->len + ii] =
2344 pItemExtRates->abyRates[ii];
2345 ii++;
Forest Bond92b96792009-06-13 07:38:31 -04002346 if (pItemExtRates->len <= ii)
2347 break;
2348 }
Andres Moreb902fbf2013-02-25 20:32:51 -05002349 pItemRates->len += (u8)ii;
Forest Bond92b96792009-06-13 07:38:31 -04002350 if (pItemExtRates->len - ii > 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05002351 pItemExtRates->len -= (u8)ii;
Forest Bond92b96792009-06-13 07:38:31 -04002352 for (uu = 0; uu < pItemExtRates->len; uu ++) {
2353 pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
2354 }
2355 } else {
2356 pItemExtRates->len = 0;
2357 }
2358 }
2359
Andres More4e9b5e22013-02-12 20:36:30 -05002360 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
Forest Bond92b96792009-06-13 07:38:31 -04002361 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2362 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2363 vUpdateIFS(pDevice);
2364 // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
2365 // TODO: deal with if wCapInfo the PS-Pollable is on.
2366 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2367 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2368 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2369 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2370
2371 pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
2372
2373 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2374 // Adopt BSS state in Adapter Device Object
2375 pDevice->eOPMode = OP_MODE_INFRASTRUCTURE;
2376 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2377
2378 // Add current BSS to Candidate list
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002379 // This should only work for WPA2 BSS, and WPA2 BSS check must be done before.
Forest Bond92b96792009-06-13 07:38:31 -04002380 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
Andres Moredfdcc422013-02-12 20:36:28 -05002381 bool bResult = bAdd_PMKID_Candidate((void *) pDevice,
Andres More0cbd8d92010-05-06 20:34:29 -03002382 pMgmt->abyCurrBSSID,
2383 &pCurr->sRSNCapObj);
Forest Bond92b96792009-06-13 07:38:31 -04002384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
Andres Moree269fc22013-02-12 20:36:29 -05002385 if (bResult == false) {
Andres More0cbd8d92010-05-06 20:34:29 -03002386 vFlush_PMKID_Candidate((void *) pDevice);
2387 DBG_PRT(MSG_LEVEL_DEBUG,
2388 KERN_INFO "vFlush_PMKID_Candidate: 4\n");
2389 bAdd_PMKID_Candidate((void *) pDevice,
2390 pMgmt->abyCurrBSSID,
2391 &pCurr->sRSNCapObj);
Forest Bond92b96792009-06-13 07:38:31 -04002392 }
2393 }
2394
2395 // Preamble type auto-switch: if AP can receive short-preamble cap,
2396 // we can turn on too.
2397 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
2398 pDevice->byPreambleType = pDevice->byShortPreamble;
2399 }
2400 else {
2401 pDevice->byPreambleType = 0;
2402 }
2403 // Change PreambleType must set RSPINF again
Andres Moreb902fbf2013-02-25 20:32:51 -05002404 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
Forest Bond92b96792009-06-13 07:38:31 -04002405
2406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
2407
2408 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11G) {
2409
2410 if ((pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
2411 pDevice->bProtectMode = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
2412 if (pDevice->bProtectMode) {
2413 MACvEnableProtectMD(pDevice);
2414 } else {
2415 MACvDisableProtectMD(pDevice);
2416 }
2417 vUpdateIFS(pDevice);
2418 }
2419 if ((pCurr->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
2420 pDevice->bNonERPPresent = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
2421 }
2422 if ((pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
2423 pDevice->bBarkerPreambleMd = (pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
2424 //BarkerPreambleMd has higher priority than shortPreamble bit in Cap
2425 if (pDevice->bBarkerPreambleMd) {
2426 MACvEnableBarkerPreambleMd(pDevice);
2427 } else {
2428 MACvDisableBarkerPreambleMd(pDevice);
2429 }
2430 }
2431 }
2432 //DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo));
2433 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) {
2434 if (pDevice->byBBType == BB_TYPE_11A) {
Andres More4e9b5e22013-02-12 20:36:30 -05002435 bShortSlotTime = true;
Forest Bond92b96792009-06-13 07:38:31 -04002436 }
2437 else if (pDevice->byBBType == BB_TYPE_11B) {
Andres Moree269fc22013-02-12 20:36:29 -05002438 bShortSlotTime = false;
Forest Bond92b96792009-06-13 07:38:31 -04002439 }
2440 else {
2441 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo);
2442 }
2443 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
2444 if (bShortSlotTime != pDevice->bShortSlotTime) {
2445 pDevice->bShortSlotTime = bShortSlotTime;
2446 BBvSetShortSlotTime(pDevice);
2447 vUpdateIFS(pDevice);
2448 }
2449 }
2450
2451 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
2452 }
2453 else {
2454 pMgmt->eCurrState = WMAC_STATE_IDLE;
2455 };
2456
Forest Bond92b96792009-06-13 07:38:31 -04002457 }
2458 else {
2459 // ad-hoc mode BSS
2460 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2461
2462 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2463/*
Andres Moree269fc22013-02-12 20:36:29 -05002464 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002465 // encryption mode error
2466 pMgmt->eCurrState = WMAC_STATE_IDLE;
2467 return;
2468 }
2469*/
2470 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2471/*
Andres Moree269fc22013-02-12 20:36:29 -05002472 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002473 // encryption mode error
2474 pMgmt->eCurrState = WMAC_STATE_IDLE;
2475 return;
2476 }
2477*/
2478 } else {
2479 // encryption mode error
2480 pMgmt->eCurrState = WMAC_STATE_IDLE;
2481 return;
2482 }
2483 }
2484
2485 s_vMgrSynchBSS(pDevice,
2486 WMAC_MODE_IBSS_STA,
2487 pCurr,
2488 pStatus
2489 );
2490
2491 if (*pStatus == CMD_STATUS_SUCCESS){
2492 // Adopt this BSS state vars in Mgmt Object
2493 // TODO: check if CapInfo privacy on, but we don't..
2494 pMgmt->uCurrChannel = pCurr->uChannel;
2495
Forest Bond92b96792009-06-13 07:38:31 -04002496 // Parse Support Rate IE
2497 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2498 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2499 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2500 WLAN_RATES_MAXLEN_11B);
2501 // set basic rate
Andres More8611a292010-05-01 14:25:00 -03002502 RATEvParseMaxRate((void *)pDevice,
2503 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
Andres More4e9b5e22013-02-12 20:36:30 -05002504 NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
Forest Bond92b96792009-06-13 07:38:31 -04002505 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2506 vUpdateIFS(pDevice);
2507 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
2508 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2509 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2510 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2511 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2512// pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
2513 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2514 pMgmt->eCurrState = WMAC_STATE_STARTED;
2515 // Adopt BSS state in Adapter Device Object
2516 pDevice->eOPMode = OP_MODE_ADHOC;
Andres More4e9b5e22013-02-12 20:36:30 -05002517 pDevice->bLinkPass = true;
Forest Bond92b96792009-06-13 07:38:31 -04002518 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
2519 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2520
Andy Shevchenkod6a32aa2011-07-26 10:35:31 +03002521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%pM\n",
2522 pMgmt->abyCurrBSSID);
Forest Bond92b96792009-06-13 07:38:31 -04002523 // Preamble type auto-switch: if AP can receive short-preamble cap,
2524 // and if registry setting is short preamble we can turn on too.
2525
2526 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
2527 pDevice->byPreambleType = pDevice->byShortPreamble;
2528 }
2529 else {
2530 pDevice->byPreambleType = 0;
2531 }
2532 // Change PreambleType must set RSPINF again
Andres Moreb902fbf2013-02-25 20:32:51 -05002533 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
Forest Bond92b96792009-06-13 07:38:31 -04002534
2535 // Prepare beacon
Andres More0cbd8d92010-05-06 20:34:29 -03002536 bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
Forest Bond92b96792009-06-13 07:38:31 -04002537 }
2538 else {
2539 pMgmt->eCurrState = WMAC_STATE_IDLE;
2540 };
2541 };
2542 return;
2543}
2544
Forest Bond92b96792009-06-13 07:38:31 -04002545/*+
2546 *
2547 * Routine Description:
2548 * Set HW to synchronize a specific BSS from known BSS list.
2549 *
2550 *
2551 * Return Value:
2552 * PCM_STATUS
2553 *
2554-*/
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002555static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode,
2556 PKnownBSS pCurr, PCMD_STATUS pStatus)
Forest Bond92b96792009-06-13 07:38:31 -04002557{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002558 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2559 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
2560 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
2561 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
2562 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
2563 4, 0x0C, 0x12, 0x18, 0x60};
2564 /* 6M, 9M, 12M, 48M*/
2565 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
2566 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2567 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
2568 4, 0x02, 0x04, 0x0B, 0x16};
Forest Bond92b96792009-06-13 07:38:31 -04002569
2570 *pStatus = CMD_STATUS_FAILURE;
2571
2572 if (s_bCipherMatch(pCurr,
2573 pDevice->eEncryptionStatus,
2574 &(pMgmt->byCSSPK),
Andres Moree269fc22013-02-12 20:36:29 -05002575 &(pMgmt->byCSSGK)) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002576 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n");
2577 return;
2578 }
2579
2580 pMgmt->pCurrBSS = pCurr;
2581
2582 // if previous mode is IBSS.
2583 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2584 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
2585 }
2586
2587 // Init the BSS informations
Andres More4e9b5e22013-02-12 20:36:30 -05002588 pDevice->bCCK = true;
Andres Moree269fc22013-02-12 20:36:29 -05002589 pDevice->bProtectMode = false;
Forest Bond92b96792009-06-13 07:38:31 -04002590 MACvDisableProtectMD(pDevice);
Andres Moree269fc22013-02-12 20:36:29 -05002591 pDevice->bBarkerPreambleMd = false;
Forest Bond92b96792009-06-13 07:38:31 -04002592 MACvDisableBarkerPreambleMd(pDevice);
Andres Moree269fc22013-02-12 20:36:29 -05002593 pDevice->bNonERPPresent = false;
Forest Bond92b96792009-06-13 07:38:31 -04002594 pDevice->byPreambleType = 0;
2595 pDevice->wBasicRate = 0;
2596 // Set Basic Rate
Andres More8611a292010-05-01 14:25:00 -03002597 CARDbAddBasicRate((void *)pDevice, RATE_1M);
Forest Bond92b96792009-06-13 07:38:31 -04002598
2599 // calculate TSF offset
2600 // TSF Offset = Received Timestamp TSF - Marked Local's TSF
2601 CARDvAdjustTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
2602
2603 // set HW beacon interval
2604 MACvWriteBeaconInterval(pDevice, pCurr->wBeaconInterval);
2605
2606 // set Next TBTT
2607 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2608 CARDvSetFirstNextTBTT(pDevice, pCurr->wBeaconInterval);
2609
2610 // set BSSID
2611 MACvWriteBSSIDAddress(pDevice, pCurr->abyBSSID);
2612
Jim Lieb3e362592009-08-12 14:54:11 -07002613 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, 6);
Forest Bond92b96792009-06-13 07:38:31 -04002614
Andy Shevchenkod6a32aa2011-07-26 10:35:31 +03002615 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = "
2616 "%pM\n", pMgmt->abyCurrBSSID);
Forest Bond92b96792009-06-13 07:38:31 -04002617
2618 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
2619 if ((pDevice->eConfigPHYMode == PHY_TYPE_11A) ||
2620 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2621 pDevice->byBBType = BB_TYPE_11A;
2622 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
Andres More4e9b5e22013-02-12 20:36:30 -05002623 pDevice->bShortSlotTime = true;
Forest Bond92b96792009-06-13 07:38:31 -04002624 BBvSetShortSlotTime(pDevice);
2625 CARDvSetBSSMode(pDevice);
2626 } else {
2627 return;
2628 }
2629 } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2630 if ((pDevice->eConfigPHYMode == PHY_TYPE_11B) ||
2631 (pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
2632 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2633 pDevice->byBBType = BB_TYPE_11B;
2634 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002635 pDevice->bShortSlotTime = false;
Forest Bond92b96792009-06-13 07:38:31 -04002636 BBvSetShortSlotTime(pDevice);
2637 CARDvSetBSSMode(pDevice);
2638 } else {
2639 return;
2640 }
2641 } else {
2642 if ((pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
2643 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2644 pDevice->byBBType = BB_TYPE_11G;
2645 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
Andres More4e9b5e22013-02-12 20:36:30 -05002646 pDevice->bShortSlotTime = true;
Forest Bond92b96792009-06-13 07:38:31 -04002647 BBvSetShortSlotTime(pDevice);
2648 CARDvSetBSSMode(pDevice);
2649 } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) {
2650 pDevice->byBBType = BB_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002651 pDevice->bShortSlotTime = false;
Forest Bond92b96792009-06-13 07:38:31 -04002652 BBvSetShortSlotTime(pDevice);
2653 CARDvSetBSSMode(pDevice);
2654 } else {
2655 return;
2656 }
2657 }
2658
2659 if (uBSSMode == WMAC_MODE_ESS_STA) {
2660 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2661 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2662 pDevice->byRxMode |= RCR_BSSID;
Andres More4e9b5e22013-02-12 20:36:30 -05002663 pMgmt->bCurrBSSIDFilterOn = true;
Forest Bond92b96792009-06-13 07:38:31 -04002664 }
2665
2666 // set channel and clear NAV
2667 CARDbSetMediaChannel(pDevice, pCurr->uChannel);
2668 pMgmt->uCurrChannel = pCurr->uChannel;
2669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
2670
2671 if ((pDevice->bUpdateBBVGA) &&
2672 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
2673 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
2674 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
2675 BBvSetShortSlotTime(pDevice);
2676 }
2677 //
2678 // Notes:
2679 // 1. In Ad-hoc mode : check if received others beacon as jointed indication,
2680 // otherwise we will start own IBSS.
2681 // 2. In Infra mode : Supposed we already synchronized with AP right now.
2682
2683 if (uBSSMode == WMAC_MODE_IBSS_STA) {
2684 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2685 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2686 pDevice->byRxMode |= RCR_BSSID;
Andres More4e9b5e22013-02-12 20:36:30 -05002687 pMgmt->bCurrBSSIDFilterOn = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002688 }
Forest Bond92b96792009-06-13 07:38:31 -04002689
2690 if (pDevice->byBBType == BB_TYPE_11A) {
Jim Lieb3e362592009-08-12 14:54:11 -07002691 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
Forest Bond92b96792009-06-13 07:38:31 -04002692 pMgmt->abyCurrExtSuppRates[1] = 0;
2693 } else if (pDevice->byBBType == BB_TYPE_11B) {
Jim Lieb3e362592009-08-12 14:54:11 -07002694 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
Forest Bond92b96792009-06-13 07:38:31 -04002695 pMgmt->abyCurrExtSuppRates[1] = 0;
2696 } else {
Jim Lieb3e362592009-08-12 14:54:11 -07002697 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
2698 memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
Forest Bond92b96792009-06-13 07:38:31 -04002699 }
2700 pMgmt->byERPContext = pCurr->sERP.byERP;
2701
2702 *pStatus = CMD_STATUS_SUCCESS;
2703
2704 return;
2705};
2706
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002707static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr)
Forest Bond92b96792009-06-13 07:38:31 -04002708 {
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002709 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Forest Bond92b96792009-06-13 07:38:31 -04002710
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002711 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
2712 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002713 if (pCurr->bWPAValid == true) { /*WPA-PSK */
Forest Bond92b96792009-06-13 07:38:31 -04002714 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
2715 if(pCurr->abyPKType[0] == WPA_TKIP) {
2716 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2717 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
2718 }
2719 else if(pCurr->abyPKType[0] == WPA_AESCCMP) {
2720 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2721 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
2722 }
2723 }
Andres More4e9b5e22013-02-12 20:36:30 -05002724 else if(pCurr->bWPA2Valid == true) { //WPA2-PSK
Forest Bond92b96792009-06-13 07:38:31 -04002725 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
2726 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
2727 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2728 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
2729 }
2730 else if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
2731 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2732 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
2733 }
2734 }
2735 }
2736 // }
2737 return;
2738 }
2739
Forest Bond92b96792009-06-13 07:38:31 -04002740/*+
2741 *
2742 * Routine Description:
2743 * Format TIM field
2744 *
2745 *
2746 * Return Value:
Andres More8611a292010-05-01 14:25:00 -03002747 * void
Forest Bond92b96792009-06-13 07:38:31 -04002748 *
2749-*/
2750
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002751static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
Forest Bond92b96792009-06-13 07:38:31 -04002752{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002753 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2754 u8 byMap;
2755 int ii, jj;
Andres Moree269fc22013-02-12 20:36:29 -05002756 int bStartFound = false;
2757 int bMulticast = false;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002758 u16 wStartIndex = 0;
2759 u16 wEndIndex = 0;
Forest Bond92b96792009-06-13 07:38:31 -04002760
Forest Bond92b96792009-06-13 07:38:31 -04002761 // Find size of partial virtual bitmap
2762 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
2763 byMap = pMgmt->abyPSTxMap[ii];
2764 if (!ii) {
2765 // Mask out the broadcast bit which is indicated separately.
2766 bMulticast = (byMap & byMask[0]) != 0;
2767 if(bMulticast) {
Andres More4e9b5e22013-02-12 20:36:30 -05002768 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
Forest Bond92b96792009-06-13 07:38:31 -04002769 }
2770 byMap = 0;
2771 }
2772 if (byMap) {
2773 if (!bStartFound) {
Andres More4e9b5e22013-02-12 20:36:30 -05002774 bStartFound = true;
Andres More3eaca0d2013-02-25 20:32:52 -05002775 wStartIndex = (u16)ii;
Forest Bond92b96792009-06-13 07:38:31 -04002776 }
Andres More3eaca0d2013-02-25 20:32:52 -05002777 wEndIndex = (u16)ii;
Forest Bond92b96792009-06-13 07:38:31 -04002778 }
Joe Perches273f4be2011-04-10 14:31:34 -07002779 }
Forest Bond92b96792009-06-13 07:38:31 -04002780
Forest Bond92b96792009-06-13 07:38:31 -04002781 // Round start index down to nearest even number
2782 wStartIndex &= ~BIT0;
2783
2784 // Round end index up to nearest even number
2785 wEndIndex = ((wEndIndex + 1) & ~BIT0);
2786
2787 // Size of element payload
2788
2789 pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
2790
2791 // Fill in the Fixed parts of the TIM
2792 pTIM->byDTIMCount = pMgmt->byDTIMCount;
2793 pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
2794 pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
2795 (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
2796
2797 // Append variable part of TIM
2798
2799 for (ii = wStartIndex, jj =0 ; ii <= wEndIndex; ii++, jj++) {
2800 pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
2801 }
2802
2803 // Aid = 0 don't used.
2804 pTIM->byVirtBitMap[0] &= ~BIT0;
2805}
2806
Forest Bond92b96792009-06-13 07:38:31 -04002807/*+
2808 *
2809 * Routine Description:
2810 * Constructs an Beacon frame( Ad-hoc mode)
2811 *
2812 *
2813 * Return Value:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002814 * PTR to frame; or NULL on allocation failure
Forest Bond92b96792009-06-13 07:38:31 -04002815 *
2816-*/
2817
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002818static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
2819 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
2820 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
2821 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
2822 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
Forest Bond92b96792009-06-13 07:38:31 -04002823{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002824 struct vnt_tx_mgmt *pTxPacket = NULL;
2825 WLAN_FR_BEACON sFrame;
2826 u8 abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Forest Bond92b96792009-06-13 07:38:31 -04002827
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002828 /* prepare beacon frame */
2829 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
2830 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
2831 + WLAN_BEACON_FR_MAXLEN);
2832 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2833 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -04002834 // Setup the sFrame structure.
Andres Moreb902fbf2013-02-25 20:32:51 -05002835 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04002836 sFrame.len = WLAN_BEACON_FR_MAXLEN;
2837 vMgrEncodeBeacon(&sFrame);
2838 // Setup the header
2839 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
2840 (
2841 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
2842 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
2843 ));
2844
2845 if (pDevice->bEnablePSMode) {
Andres More3eaca0d2013-02-25 20:32:52 -05002846 sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((u16)WLAN_SET_FC_PWRMGT(1));
Forest Bond92b96792009-06-13 07:38:31 -04002847 }
2848
2849 memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
2850 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2851 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
2852 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
2853 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
2854 // Copy SSID
2855 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
2856 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
2857 memcpy(sFrame.pSSID,
2858 pCurrSSID,
2859 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
2860 );
2861 // Copy the rate set
2862 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2863 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
2864 memcpy(sFrame.pSuppRates,
2865 pCurrSuppRates,
2866 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
2867 );
2868 // DS parameter
2869 if (pDevice->byBBType != BB_TYPE_11A) {
2870 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
2871 sFrame.len += (1) + WLAN_IEHDR_LEN;
2872 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
2873 sFrame.pDSParms->len = 1;
Andres Moreb902fbf2013-02-25 20:32:51 -05002874 sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
Forest Bond92b96792009-06-13 07:38:31 -04002875 }
2876 // TIM field
2877 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2878 sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
2879 sFrame.pTIM->byElementID = WLAN_EID_TIM;
2880 s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
2881 sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
2882 }
2883
2884 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2885
2886 // IBSS parameter
2887 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
2888 sFrame.len += (2) + WLAN_IEHDR_LEN;
2889 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
2890 sFrame.pIBSSParms->len = 2;
2891 sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
2892 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2893 /* RSN parameter */
2894 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
2895 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
2896 sFrame.pRSNWPA->len = 12;
2897 sFrame.pRSNWPA->abyOUI[0] = 0x00;
2898 sFrame.pRSNWPA->abyOUI[1] = 0x50;
2899 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
2900 sFrame.pRSNWPA->abyOUI[3] = 0x01;
2901 sFrame.pRSNWPA->wVersion = 1;
2902 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
2903 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
2904 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
2905 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
2906 sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
2907 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
2908 sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
2909 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
2910 sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
2911 else
2912 sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
2913
2914 // Pairwise Key Cipher Suite
2915 sFrame.pRSNWPA->wPKCount = 0;
2916 // Auth Key Management Suite
Andres More3eaca0d2013-02-25 20:32:52 -05002917 *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
Forest Bond92b96792009-06-13 07:38:31 -04002918 sFrame.pRSNWPA->len +=2;
2919
2920 // RSN Capabilites
Andres More3eaca0d2013-02-25 20:32:52 -05002921 *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
Forest Bond92b96792009-06-13 07:38:31 -04002922 sFrame.pRSNWPA->len +=2;
2923 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
2924 }
2925 }
2926
Forest Bond92b96792009-06-13 07:38:31 -04002927 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2928 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
2929 sFrame.len += 1 + WLAN_IEHDR_LEN;
2930 sFrame.pERP->byElementID = WLAN_EID_ERP;
2931 sFrame.pERP->len = 1;
2932 sFrame.pERP->byContext = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002933 if (pDevice->bProtectMode == true)
Forest Bond92b96792009-06-13 07:38:31 -04002934 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
Andres More4e9b5e22013-02-12 20:36:30 -05002935 if (pDevice->bNonERPPresent == true)
Forest Bond92b96792009-06-13 07:38:31 -04002936 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
Andres More4e9b5e22013-02-12 20:36:30 -05002937 if (pDevice->bBarkerPreambleMd == true)
Forest Bond92b96792009-06-13 07:38:31 -04002938 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
2939 }
2940 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
2941 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2942 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07002943 memcpy(sFrame.pExtSuppRates,
Forest Bond92b96792009-06-13 07:38:31 -04002944 pCurrExtSuppRates,
2945 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2946 );
2947 }
2948 // hostapd wpa/wpa2 IE
Andres More4e9b5e22013-02-12 20:36:30 -05002949 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04002950 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2951 if (pMgmt->wWPAIELen != 0) {
2952 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
2953 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
2954 sFrame.len += pMgmt->wWPAIELen;
2955 }
2956 }
2957 }
2958
2959 /* Adjust the length fields */
2960 pTxPacket->cbMPDULen = sFrame.len;
2961 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
2962
2963 return pTxPacket;
2964}
2965
Forest Bond92b96792009-06-13 07:38:31 -04002966/*+
2967 *
2968 * Routine Description:
2969 * Constructs an Prob-response frame
2970 *
2971 *
2972 * Return Value:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002973 * PTR to frame; or NULL on allocation failure
Forest Bond92b96792009-06-13 07:38:31 -04002974 *
2975-*/
2976
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002977struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
2978 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
2979 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
2980 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
2981 PWLAN_IE_SUPP_RATES pCurrSuppRates,
2982 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType)
Forest Bond92b96792009-06-13 07:38:31 -04002983{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002984 struct vnt_tx_mgmt *pTxPacket = NULL;
2985 WLAN_FR_PROBERESP sFrame;
Forest Bond92b96792009-06-13 07:38:31 -04002986
Malcolm Priestley78f41c92012-12-10 22:03:56 +00002987 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
2988 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
2989 + WLAN_PROBERESP_FR_MAXLEN);
2990 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2991 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -04002992 // Setup the sFrame structure.
Andres Moreb902fbf2013-02-25 20:32:51 -05002993 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04002994 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
2995 vMgrEncodeProbeResponse(&sFrame);
2996 // Setup the header
2997 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
2998 (
2999 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3000 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
3001 ));
3002 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3003 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3004 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3005 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3006 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3007
3008 if (byPHYType == BB_TYPE_11B) {
Andres More3eaca0d2013-02-25 20:32:52 -05003009 *sFrame.pwCapInfo &= cpu_to_le16((u16)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
Forest Bond92b96792009-06-13 07:38:31 -04003010 }
3011
3012 // Copy SSID
3013 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3014 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3015 memcpy(sFrame.pSSID,
3016 pCurrSSID,
3017 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3018 );
3019 // Copy the rate set
3020 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3021
3022 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3023 memcpy(sFrame.pSuppRates,
3024 pCurrSuppRates,
3025 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3026 );
3027
3028 // DS parameter
3029 if (pDevice->byBBType != BB_TYPE_11A) {
3030 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3031 sFrame.len += (1) + WLAN_IEHDR_LEN;
3032 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3033 sFrame.pDSParms->len = 1;
Andres Moreb902fbf2013-02-25 20:32:51 -05003034 sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
Forest Bond92b96792009-06-13 07:38:31 -04003035 }
3036
3037 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3038 // IBSS parameter
3039 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3040 sFrame.len += (2) + WLAN_IEHDR_LEN;
3041 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3042 sFrame.pIBSSParms->len = 2;
3043 sFrame.pIBSSParms->wATIMWindow = 0;
3044 }
3045 if (pDevice->byBBType == BB_TYPE_11G) {
3046 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3047 sFrame.len += 1 + WLAN_IEHDR_LEN;
3048 sFrame.pERP->byElementID = WLAN_EID_ERP;
3049 sFrame.pERP->len = 1;
3050 sFrame.pERP->byContext = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05003051 if (pDevice->bProtectMode == true)
Forest Bond92b96792009-06-13 07:38:31 -04003052 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
Andres More4e9b5e22013-02-12 20:36:30 -05003053 if (pDevice->bNonERPPresent == true)
Forest Bond92b96792009-06-13 07:38:31 -04003054 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
Andres More4e9b5e22013-02-12 20:36:30 -05003055 if (pDevice->bBarkerPreambleMd == true)
Forest Bond92b96792009-06-13 07:38:31 -04003056 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3057 }
3058
3059 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3060 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3061 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003062 memcpy(sFrame.pExtSuppRates,
Forest Bond92b96792009-06-13 07:38:31 -04003063 pCurrExtSuppRates,
3064 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3065 );
3066 }
3067
3068 // hostapd wpa/wpa2 IE
Andres More4e9b5e22013-02-12 20:36:30 -05003069 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04003070 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3071 if (pMgmt->wWPAIELen != 0) {
3072 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3073 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3074 sFrame.len += pMgmt->wWPAIELen;
3075 }
3076 }
3077 }
3078
3079 // Adjust the length fields
3080 pTxPacket->cbMPDULen = sFrame.len;
3081 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3082
3083 return pTxPacket;
3084}
3085
Forest Bond92b96792009-06-13 07:38:31 -04003086/*+
3087 *
3088 * Routine Description:
3089 * Constructs an association request frame
3090 *
3091 *
3092 * Return Value:
Masanari Iidaa0ae9e3c2013-09-15 20:31:37 +09003093 * A ptr to frame or NULL on allocation failure
Forest Bond92b96792009-06-13 07:38:31 -04003094 *
3095-*/
3096
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003097struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
3098 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3099 u16 wListenInterval,
3100 PWLAN_IE_SSID pCurrSSID,
3101 PWLAN_IE_SUPP_RATES pCurrRates,
3102 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
Forest Bond92b96792009-06-13 07:38:31 -04003103{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003104 struct vnt_tx_mgmt *pTxPacket = NULL;
3105 WLAN_FR_ASSOCREQ sFrame;
3106 u8 *pbyIEs;
3107 u8 *pbyRSN;
Forest Bond92b96792009-06-13 07:38:31 -04003108
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003109 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3110 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3111 + WLAN_ASSOCREQ_FR_MAXLEN);
3112 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3113 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -04003114 // Setup the sFrame structure.
Andres Moreb902fbf2013-02-25 20:32:51 -05003115 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04003116 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
3117 // format fixed field frame structure
3118 vMgrEncodeAssocRequest(&sFrame);
3119 // Setup the header
3120 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3121 (
3122 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3123 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
3124 ));
3125 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3126 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3127 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3128
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07003129 // Set the capability and listen interval
Forest Bond92b96792009-06-13 07:38:31 -04003130 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3131 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3132
3133 // sFrame.len point to end of fixed field
3134 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3135 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3136 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3137
3138 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3139 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3140 pbyIEs = pMgmt->sAssocInfo.abyIEs;
Jim Lieb3e362592009-08-12 14:54:11 -07003141 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003142 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3143
3144 // Copy the rate set
3145 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3146 if ((pDevice->byBBType == BB_TYPE_11B) && (pCurrRates->len > 4))
3147 sFrame.len += 4 + WLAN_IEHDR_LEN;
3148 else
3149 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3150 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3151
3152 // Copy the extension rate set
3153 if ((pDevice->byBBType == BB_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3154 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3155 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3156 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3157 }
3158
3159 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003160 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003161 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3162
Forest Bond92b96792009-06-13 07:38:31 -04003163 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3164 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3165 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3166 (pMgmt->pCurrBSS != NULL)) {
3167 /* WPA IE */
3168 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3169 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3170 sFrame.pRSNWPA->len = 16;
3171 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3172 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3173 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3174 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3175 sFrame.pRSNWPA->wVersion = 1;
3176 //Group Key Cipher Suite
3177 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3178 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3179 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3180 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3181 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3182 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3183 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3184 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3185 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3186 } else {
3187 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3188 }
3189 // Pairwise Key Cipher Suite
3190 sFrame.pRSNWPA->wPKCount = 1;
3191 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3192 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3193 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3194 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3195 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3196 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3197 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3198 } else {
3199 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3200 }
3201 // Auth Key Management Suite
Andres Moreb902fbf2013-02-25 20:32:51 -05003202 pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
Forest Bond92b96792009-06-13 07:38:31 -04003203 *pbyRSN++=0x01;
3204 *pbyRSN++=0x00;
3205 *pbyRSN++=0x00;
3206
3207 *pbyRSN++=0x50;
3208 *pbyRSN++=0xf2;
3209 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3210 *pbyRSN++=WPA_AUTH_PSK;
3211 }
3212 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3213 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3214 }
3215 else {
3216 *pbyRSN++=WPA_NONE;
3217 }
3218
3219 sFrame.pRSNWPA->len +=6;
3220
3221 // RSN Capabilites
3222
3223 *pbyRSN++=0x00;
3224 *pbyRSN++=0x00;
3225 sFrame.pRSNWPA->len +=2;
3226
3227 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3228 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3229 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003230 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003231 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3232
3233 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3234 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3235 (pMgmt->pCurrBSS != NULL)) {
Andres Morecc856e62010-05-17 21:34:01 -03003236 unsigned int ii;
Andres More3eaca0d2013-02-25 20:32:52 -05003237 u16 * pwPMKID;
Forest Bond92b96792009-06-13 07:38:31 -04003238
3239 // WPA IE
3240 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3241 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3242 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3243 sFrame.pRSN->wVersion = 1;
3244 //Group Key Cipher Suite
3245 sFrame.pRSN->abyRSN[0] = 0x00;
3246 sFrame.pRSN->abyRSN[1] = 0x0F;
3247 sFrame.pRSN->abyRSN[2] = 0xAC;
3248 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3249 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3250 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3251 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3252 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3253 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3254 } else {
3255 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3256 }
3257
3258 // Pairwise Key Cipher Suite
3259 sFrame.pRSN->abyRSN[4] = 1;
3260 sFrame.pRSN->abyRSN[5] = 0;
3261 sFrame.pRSN->abyRSN[6] = 0x00;
3262 sFrame.pRSN->abyRSN[7] = 0x0F;
3263 sFrame.pRSN->abyRSN[8] = 0xAC;
3264 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3265 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3266 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3267 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3268 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3269 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3270 } else {
3271 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3272 }
3273 sFrame.pRSN->len += 6;
3274
3275 // Auth Key Management Suite
3276 sFrame.pRSN->abyRSN[10] = 1;
3277 sFrame.pRSN->abyRSN[11] = 0;
3278 sFrame.pRSN->abyRSN[12] = 0x00;
3279 sFrame.pRSN->abyRSN[13] = 0x0F;
3280 sFrame.pRSN->abyRSN[14] = 0xAC;
3281 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3282 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3283 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3284 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3285 } else {
3286 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3287 }
3288 sFrame.pRSN->len +=6;
3289
3290 // RSN Capabilites
Andres More4e9b5e22013-02-12 20:36:30 -05003291 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
Jim Lieb3e362592009-08-12 14:54:11 -07003292 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
Forest Bond92b96792009-06-13 07:38:31 -04003293 } else {
3294 sFrame.pRSN->abyRSN[16] = 0;
3295 sFrame.pRSN->abyRSN[17] = 0;
3296 }
3297 sFrame.pRSN->len +=2;
3298
Andres More4e9b5e22013-02-12 20:36:30 -05003299 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
Forest Bond92b96792009-06-13 07:38:31 -04003300 // RSN PMKID
3301 pbyRSN = &sFrame.pRSN->abyRSN[18];
Andres More3eaca0d2013-02-25 20:32:52 -05003302 pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
Forest Bond92b96792009-06-13 07:38:31 -04003303 *pwPMKID = 0; // Initialize PMKID count
3304 pbyRSN += 2; // Point to PMKID list
Andres More9a0e7562010-04-13 21:54:48 -03003305 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3306 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0],
3307 pMgmt->abyCurrBSSID,
3308 ETH_ALEN)) {
3309 (*pwPMKID)++;
3310 memcpy(pbyRSN,
3311 pDevice->gsPMKID.BSSIDInfo[ii].PMKID,
3312 16);
3313 pbyRSN += 16;
3314 }
3315 }
Forest Bond92b96792009-06-13 07:38:31 -04003316 if (*pwPMKID != 0) {
3317 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3318 }
3319 }
3320
3321 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3322 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3323 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003324 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003325 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3326 }
3327
Forest Bond92b96792009-06-13 07:38:31 -04003328 // Adjust the length fields
3329 pTxPacket->cbMPDULen = sFrame.len;
3330 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3331 return pTxPacket;
3332}
3333
Forest Bond92b96792009-06-13 07:38:31 -04003334/*+
3335 *
3336 * Routine Description:
3337 * Constructs an re-association request frame
3338 *
3339 *
3340 * Return Value:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07003341 * A ptr to frame or NULL on allocation failure
Forest Bond92b96792009-06-13 07:38:31 -04003342 *
3343-*/
3344
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003345struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
3346 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3347 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
3348 PWLAN_IE_SUPP_RATES pCurrRates,
3349 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
Forest Bond92b96792009-06-13 07:38:31 -04003350{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003351 struct vnt_tx_mgmt *pTxPacket = NULL;
3352 WLAN_FR_REASSOCREQ sFrame;
3353 u8 *pbyIEs;
3354 u8 *pbyRSN;
Forest Bond92b96792009-06-13 07:38:31 -04003355
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003356 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3357 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3358 + WLAN_REASSOCREQ_FR_MAXLEN);
3359 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3360 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -04003361 /* Setup the sFrame structure. */
Andres Moreb902fbf2013-02-25 20:32:51 -05003362 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04003363 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
3364
3365 // format fixed field frame structure
3366 vMgrEncodeReassocRequest(&sFrame);
3367
3368 /* Setup the header */
3369 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3370 (
3371 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3372 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
3373 ));
3374 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3375 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3376 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3377
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07003378 /* Set the capability and listen interval */
Forest Bond92b96792009-06-13 07:38:31 -04003379 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3380 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3381
3382 memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3383 /* Copy the SSID */
3384 /* sFrame.len point to end of fixed field */
3385 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3386 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3387 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3388
3389 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3390 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3391 pbyIEs = pMgmt->sAssocInfo.abyIEs;
Jim Lieb3e362592009-08-12 14:54:11 -07003392 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003393 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3394
3395 /* Copy the rate set */
3396 /* sFrame.len point to end of SSID */
3397 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3398 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3399 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3400
3401 // Copy the extension rate set
3402 if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3403 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3404 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3405 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3406 }
3407
3408 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003409 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003410 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3411
3412 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3413 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3414 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3415 (pMgmt->pCurrBSS != NULL)) {
3416 /* WPA IE */
3417 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3418 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3419 sFrame.pRSNWPA->len = 16;
3420 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3421 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3422 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3423 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3424 sFrame.pRSNWPA->wVersion = 1;
3425 //Group Key Cipher Suite
3426 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3427 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3428 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3429 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3430 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3431 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3432 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3433 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3434 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3435 } else {
3436 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3437 }
3438 // Pairwise Key Cipher Suite
3439 sFrame.pRSNWPA->wPKCount = 1;
3440 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3441 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3442 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3443 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3444 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3445 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3446 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3447 } else {
3448 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3449 }
3450 // Auth Key Management Suite
Andres Moreb902fbf2013-02-25 20:32:51 -05003451 pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
Forest Bond92b96792009-06-13 07:38:31 -04003452 *pbyRSN++=0x01;
3453 *pbyRSN++=0x00;
3454 *pbyRSN++=0x00;
3455
3456 *pbyRSN++=0x50;
3457 *pbyRSN++=0xf2;
3458 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3459 *pbyRSN++=WPA_AUTH_PSK;
3460 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3461 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3462 } else {
3463 *pbyRSN++=WPA_NONE;
3464 }
3465
3466 sFrame.pRSNWPA->len +=6;
3467
3468 // RSN Capabilites
3469 *pbyRSN++=0x00;
3470 *pbyRSN++=0x00;
3471 sFrame.pRSNWPA->len +=2;
3472
3473 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3474 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3475 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003476 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003477 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3478
3479 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3480 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3481 (pMgmt->pCurrBSS != NULL)) {
Andres Morecc856e62010-05-17 21:34:01 -03003482 unsigned int ii;
Andres More3eaca0d2013-02-25 20:32:52 -05003483 u16 * pwPMKID;
Forest Bond92b96792009-06-13 07:38:31 -04003484
3485 /* WPA IE */
3486 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3487 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3488 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3489 sFrame.pRSN->wVersion = 1;
3490 //Group Key Cipher Suite
3491 sFrame.pRSN->abyRSN[0] = 0x00;
3492 sFrame.pRSN->abyRSN[1] = 0x0F;
3493 sFrame.pRSN->abyRSN[2] = 0xAC;
3494 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3495 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3496 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3497 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3498 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3499 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3500 } else {
3501 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3502 }
3503
3504 // Pairwise Key Cipher Suite
3505 sFrame.pRSN->abyRSN[4] = 1;
3506 sFrame.pRSN->abyRSN[5] = 0;
3507 sFrame.pRSN->abyRSN[6] = 0x00;
3508 sFrame.pRSN->abyRSN[7] = 0x0F;
3509 sFrame.pRSN->abyRSN[8] = 0xAC;
3510 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3511 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3512 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3513 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3514 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3515 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3516 } else {
3517 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3518 }
3519 sFrame.pRSN->len += 6;
3520
3521 // Auth Key Management Suite
3522 sFrame.pRSN->abyRSN[10] = 1;
3523 sFrame.pRSN->abyRSN[11] = 0;
3524 sFrame.pRSN->abyRSN[12] = 0x00;
3525 sFrame.pRSN->abyRSN[13] = 0x0F;
3526 sFrame.pRSN->abyRSN[14] = 0xAC;
3527 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3528 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3529 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3530 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3531 } else {
3532 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3533 }
3534 sFrame.pRSN->len +=6;
3535
3536 // RSN Capabilites
Andres More4e9b5e22013-02-12 20:36:30 -05003537 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
Jim Lieb3e362592009-08-12 14:54:11 -07003538 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
Forest Bond92b96792009-06-13 07:38:31 -04003539 } else {
3540 sFrame.pRSN->abyRSN[16] = 0;
3541 sFrame.pRSN->abyRSN[17] = 0;
3542 }
3543 sFrame.pRSN->len +=2;
3544
Andres More4e9b5e22013-02-12 20:36:30 -05003545 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
Forest Bond92b96792009-06-13 07:38:31 -04003546 // RSN PMKID
3547 pbyRSN = &sFrame.pRSN->abyRSN[18];
Andres More3eaca0d2013-02-25 20:32:52 -05003548 pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
Forest Bond92b96792009-06-13 07:38:31 -04003549 *pwPMKID = 0; // Initialize PMKID count
3550 pbyRSN += 2; // Point to PMKID list
3551 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
Andres More9a0e7562010-04-13 21:54:48 -03003552 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0],
3553 pMgmt->abyCurrBSSID,
3554 ETH_ALEN)) {
3555 (*pwPMKID)++;
3556 memcpy(pbyRSN,
3557 pDevice->gsPMKID.BSSIDInfo[ii].PMKID,
3558 16);
3559 pbyRSN += 16;
Forest Bond92b96792009-06-13 07:38:31 -04003560 }
3561 }
3562 if (*pwPMKID != 0) {
3563 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3564 }
3565 }
3566
3567 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3568 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3569 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003570 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04003571 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3572 }
3573
Forest Bond92b96792009-06-13 07:38:31 -04003574 /* Adjust the length fields */
3575 pTxPacket->cbMPDULen = sFrame.len;
3576 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3577
3578 return pTxPacket;
3579}
3580
Forest Bond92b96792009-06-13 07:38:31 -04003581/*+
3582 *
3583 * Routine Description:
3584 * Constructs an assoc-response frame
3585 *
3586 *
3587 * Return Value:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07003588 * PTR to frame; or NULL on allocation failure
Forest Bond92b96792009-06-13 07:38:31 -04003589 *
3590-*/
3591
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003592struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
3593 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3594 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3595 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
Forest Bond92b96792009-06-13 07:38:31 -04003596{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003597 struct vnt_tx_mgmt *pTxPacket = NULL;
3598 WLAN_FR_ASSOCRESP sFrame;
Forest Bond92b96792009-06-13 07:38:31 -04003599
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003600 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3601 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3602 + WLAN_ASSOCREQ_FR_MAXLEN);
3603 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3604 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -04003605 // Setup the sFrame structure
Andres Moreb902fbf2013-02-25 20:32:51 -05003606 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04003607 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3608 vMgrEncodeAssocResponse(&sFrame);
3609 // Setup the header
3610 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3611 (
3612 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3613 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
3614 ));
3615 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3616 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3617 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3618
3619 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3620 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
Andres More3eaca0d2013-02-25 20:32:52 -05003621 *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
Forest Bond92b96792009-06-13 07:38:31 -04003622
3623 // Copy the rate set
3624 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3625 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3626 memcpy(sFrame.pSuppRates,
3627 pCurrSuppRates,
3628 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3629 );
3630
3631 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3632 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3633 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003634 memcpy(sFrame.pExtSuppRates,
Forest Bond92b96792009-06-13 07:38:31 -04003635 pCurrExtSuppRates,
3636 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3637 );
3638 }
3639
3640 // Adjust the length fields
3641 pTxPacket->cbMPDULen = sFrame.len;
3642 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3643
3644 return pTxPacket;
3645}
3646
Forest Bond92b96792009-06-13 07:38:31 -04003647/*+
3648 *
3649 * Routine Description:
3650 * Constructs an reassoc-response frame
3651 *
3652 *
3653 * Return Value:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07003654 * PTR to frame; or NULL on allocation failure
Forest Bond92b96792009-06-13 07:38:31 -04003655 *
3656-*/
3657
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003658struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
3659 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3660 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3661 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
Forest Bond92b96792009-06-13 07:38:31 -04003662{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003663 struct vnt_tx_mgmt *pTxPacket = NULL;
3664 WLAN_FR_REASSOCRESP sFrame;
Forest Bond92b96792009-06-13 07:38:31 -04003665
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003666 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3667 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3668 + WLAN_ASSOCREQ_FR_MAXLEN);
3669 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3670 + sizeof(struct vnt_tx_mgmt));
Forest Bond92b96792009-06-13 07:38:31 -04003671 // Setup the sFrame structure
Andres Moreb902fbf2013-02-25 20:32:51 -05003672 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04003673 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3674 vMgrEncodeReassocResponse(&sFrame);
3675 // Setup the header
3676 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3677 (
3678 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3679 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
3680 ));
3681 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3682 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3683 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3684
3685 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3686 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
Andres More3eaca0d2013-02-25 20:32:52 -05003687 *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
Forest Bond92b96792009-06-13 07:38:31 -04003688
3689 // Copy the rate set
3690 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3691 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3692 memcpy(sFrame.pSuppRates,
3693 pCurrSuppRates,
3694 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3695 );
3696
3697 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3698 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3699 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
Jim Lieb3e362592009-08-12 14:54:11 -07003700 memcpy(sFrame.pExtSuppRates,
Forest Bond92b96792009-06-13 07:38:31 -04003701 pCurrExtSuppRates,
3702 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3703 );
3704 }
3705
3706 // Adjust the length fields
3707 pTxPacket->cbMPDULen = sFrame.len;
3708 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3709
3710 return pTxPacket;
3711}
3712
Forest Bond92b96792009-06-13 07:38:31 -04003713/*+
3714 *
3715 * Routine Description:
3716 * Handles probe response management frames.
3717 *
3718 *
3719 * Return Value:
3720 * none.
3721 *
3722-*/
3723
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003724static void s_vMgrRxProbeResponse(struct vnt_private *pDevice,
3725 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
Forest Bond92b96792009-06-13 07:38:31 -04003726{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003727 PKnownBSS pBSSList = NULL;
3728 WLAN_FR_PROBERESP sFrame;
3729 u8 byCurrChannel = pRxPacket->byRxChannel;
3730 ERPObject sERP;
Andres More4e9b5e22013-02-12 20:36:30 -05003731 int bChannelHit = true;
Forest Bond92b96792009-06-13 07:38:31 -04003732
Forest Bond92b96792009-06-13 07:38:31 -04003733 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
3734 // decode the frame
3735 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05003736 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04003737 vMgrDecodeProbeResponse(&sFrame);
3738
Andres More6e1b4e22010-05-04 20:40:11 -03003739 if ((sFrame.pqwTimestamp == NULL)
3740 || (sFrame.pwBeaconInterval == NULL)
3741 || (sFrame.pwCapInfo == NULL)
3742 || (sFrame.pSSID == NULL)
3743 || (sFrame.pSuppRates == NULL)) {
3744
3745 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p]\n",
3746 pRxPacket->p80211Header);
Andres More6e1b4e22010-05-04 20:40:11 -03003747 return;
Joe Perches9fc86022011-04-10 14:31:32 -07003748 }
Forest Bond92b96792009-06-13 07:38:31 -04003749
3750 if(sFrame.pSSID->len == 0)
3751 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
3752
Forest Bond92b96792009-06-13 07:38:31 -04003753 //{{ RobertYu:20050201, 11a byCurrChannel != sFrame.pDSParms->byCurrChannel mapping
3754 if( byCurrChannel > CB_MAX_CHANNEL_24G )
3755 {
Andres More6e1b4e22010-05-04 20:40:11 -03003756 if (sFrame.pDSParms) {
3757 if (byCurrChannel ==
3758 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
Andres More4e9b5e22013-02-12 20:36:30 -05003759 bChannelHit = true;
Andres More6e1b4e22010-05-04 20:40:11 -03003760 byCurrChannel =
3761 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
Forest Bond92b96792009-06-13 07:38:31 -04003762 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05003763 bChannelHit = true;
Forest Bond92b96792009-06-13 07:38:31 -04003764 }
Forest Bond92b96792009-06-13 07:38:31 -04003765 } else {
Andres More6e1b4e22010-05-04 20:40:11 -03003766 if (sFrame.pDSParms) {
3767 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
Andres More4e9b5e22013-02-12 20:36:30 -05003768 bChannelHit = true;
Andres More6e1b4e22010-05-04 20:40:11 -03003769 byCurrChannel = sFrame.pDSParms->byCurrChannel;
3770 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05003771 bChannelHit = true;
Andres More6e1b4e22010-05-04 20:40:11 -03003772 }
Forest Bond92b96792009-06-13 07:38:31 -04003773 }
3774 //RobertYu:20050201
3775
Andres More4e9b5e22013-02-12 20:36:30 -05003776if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
Forest Bond92b96792009-06-13 07:38:31 -04003777 return;
3778
Andres More6e1b4e22010-05-04 20:40:11 -03003779 if (sFrame.pERP) {
Forest Bond92b96792009-06-13 07:38:31 -04003780 sERP.byERP = sFrame.pERP->byContext;
Andres More4e9b5e22013-02-12 20:36:30 -05003781 sERP.bERPExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04003782 } else {
Andres Moree269fc22013-02-12 20:36:29 -05003783 sERP.bERPExist = false;
Forest Bond92b96792009-06-13 07:38:31 -04003784 sERP.byERP = 0;
3785 }
3786
Forest Bond92b96792009-06-13 07:38:31 -04003787 // update or insert the bss
Andres More0cbd8d92010-05-06 20:34:29 -03003788 pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
3789 sFrame.pHdr->sA3.abyAddr3,
3790 sFrame.pSSID);
Forest Bond92b96792009-06-13 07:38:31 -04003791 if (pBSSList) {
Andres More0cbd8d92010-05-06 20:34:29 -03003792 BSSbUpdateToBSSList((void *) pDevice,
3793 *sFrame.pqwTimestamp,
3794 *sFrame.pwBeaconInterval,
3795 *sFrame.pwCapInfo,
3796 byCurrChannel,
3797 bChannelHit,
3798 sFrame.pSSID,
3799 sFrame.pSuppRates,
3800 sFrame.pExtSuppRates,
3801 &sERP,
3802 sFrame.pRSN,
3803 sFrame.pRSNWPA,
3804 sFrame.pIE_Country,
3805 sFrame.pIE_Quiet,
3806 pBSSList,
3807 sFrame.len - WLAN_HDR_ADDR3_LEN,
3808 /* payload of probresponse */
3809 sFrame.pHdr->sA4.abyAddr4,
3810 (void *) pRxPacket);
3811 } else {
Forest Bond92b96792009-06-13 07:38:31 -04003812 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
Andres More0cbd8d92010-05-06 20:34:29 -03003813 BSSbInsertToBSSList((void *) pDevice,
Forest Bond92b96792009-06-13 07:38:31 -04003814 sFrame.pHdr->sA3.abyAddr3,
3815 *sFrame.pqwTimestamp,
3816 *sFrame.pwBeaconInterval,
3817 *sFrame.pwCapInfo,
3818 byCurrChannel,
3819 sFrame.pSSID,
3820 sFrame.pSuppRates,
3821 sFrame.pExtSuppRates,
3822 &sERP,
3823 sFrame.pRSN,
3824 sFrame.pRSNWPA,
3825 sFrame.pIE_Country,
3826 sFrame.pIE_Quiet,
3827 sFrame.len - WLAN_HDR_ADDR3_LEN,
Andres More0cbd8d92010-05-06 20:34:29 -03003828 sFrame.pHdr->sA4.abyAddr4, /* payload of beacon */
3829 (void *) pRxPacket);
Forest Bond92b96792009-06-13 07:38:31 -04003830 }
3831 return;
3832
3833}
3834
3835/*+
3836 *
3837 * Routine Description:(AP)or(Ad-hoc STA)
3838 * Handles probe request management frames.
3839 *
3840 *
3841 * Return Value:
3842 * none.
3843 *
3844-*/
3845
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003846static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
3847 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
Forest Bond92b96792009-06-13 07:38:31 -04003848{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003849 WLAN_FR_PROBEREQ sFrame;
3850 CMD_STATUS Status;
3851 struct vnt_tx_mgmt *pTxPacket;
3852 u8 byPHYType = BB_TYPE_11B;
Forest Bond92b96792009-06-13 07:38:31 -04003853
3854 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
3855 // STA have to response this request.
3856 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
3857 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
3858
3859 memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
3860 // decode the frame
3861 sFrame.len = pRxPacket->cbMPDULen;
Andres Moreb902fbf2013-02-25 20:32:51 -05003862 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
Forest Bond92b96792009-06-13 07:38:31 -04003863 vMgrDecodeProbeRequest(&sFrame);
3864/*
Andy Shevchenkod6a32aa2011-07-26 10:35:31 +03003865 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%pM\n",
3866 sFrame.pHdr->sA3.abyAddr2);
Forest Bond92b96792009-06-13 07:38:31 -04003867*/
3868 if (sFrame.pSSID->len != 0) {
3869 if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
3870 return;
3871 if (memcmp(sFrame.pSSID->abySSID,
3872 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
3873 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
3874 return;
3875 }
3876 }
3877
3878 if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
3879 byPHYType = BB_TYPE_11G;
3880 }
3881
3882 // Probe response reply..
3883 pTxPacket = s_MgrMakeProbeResponse
3884 (
3885 pDevice,
3886 pMgmt,
3887 pMgmt->wCurrCapInfo,
3888 pMgmt->wCurrBeaconPeriod,
3889 pMgmt->uCurrChannel,
3890 0,
3891 sFrame.pHdr->sA3.abyAddr2,
3892 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
Andres Moreb902fbf2013-02-25 20:32:51 -05003893 (u8 *)pMgmt->abyCurrBSSID,
Forest Bond92b96792009-06-13 07:38:31 -04003894 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
3895 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
3896 byPHYType
3897 );
3898 if (pTxPacket != NULL ){
3899 /* send the frame */
3900 Status = csMgmt_xmit(pDevice, pTxPacket);
3901 if (Status != CMD_STATUS_PENDING) {
3902 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
3903 }
3904 else {
3905// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
3906 }
3907 }
3908 }
3909
3910 return;
3911}
3912
Forest Bond92b96792009-06-13 07:38:31 -04003913/*+
3914 *
3915 * Routine Description:
3916 *
3917 * Entry point for the reception and handling of 802.11 management
3918 * frames. Makes a determination of the frame type and then calls
3919 * the appropriate function.
3920 *
3921 *
3922 * Return Value:
3923 * none.
3924 *
3925-*/
3926
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003927void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt,
3928 struct vnt_rx_mgmt *pRxPacket)
Forest Bond92b96792009-06-13 07:38:31 -04003929{
Andres Moree269fc22013-02-12 20:36:29 -05003930 int bInScan = false;
Malcolm Priestley78f41c92012-12-10 22:03:56 +00003931 u32 uNodeIndex = 0;
3932 NODE_STATE eNodeState = 0;
3933 CMD_STATUS Status;
Forest Bond92b96792009-06-13 07:38:31 -04003934
Forest Bond92b96792009-06-13 07:38:31 -04003935 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
3936 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
3937 eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
3938 }
3939
3940 switch( WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) ){
3941
3942 case WLAN_FSTYPE_ASSOCREQ:
3943 // Frame Clase = 2
3944 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
3945 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
3946 (eNodeState < NODE_AUTH)) {
3947 // send deauth notification
3948 // reason = (6) class 2 received from nonauth sta
3949 vMgrDeAuthenBeginSta(pDevice,
3950 pMgmt,
3951 pRxPacket->p80211Header->sA3.abyAddr2,
3952 (6),
3953 &Status
3954 );
3955 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
3956 }
3957 else {
3958 s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
3959 }
3960 break;
3961
3962 case WLAN_FSTYPE_ASSOCRESP:
3963 // Frame Clase = 2
3964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
Andres Moree269fc22013-02-12 20:36:29 -05003965 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
Forest Bond92b96792009-06-13 07:38:31 -04003966 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
3967 break;
3968
3969 case WLAN_FSTYPE_REASSOCREQ:
3970 // Frame Clase = 2
3971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
3972 // Todo: reassoc
3973 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
3974 (eNodeState < NODE_AUTH)) {
3975 // send deauth notification
3976 // reason = (6) class 2 received from nonauth sta
3977 vMgrDeAuthenBeginSta(pDevice,
3978 pMgmt,
3979 pRxPacket->p80211Header->sA3.abyAddr2,
3980 (6),
3981 &Status
3982 );
3983 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
3984
3985 }
3986 s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
3987 break;
3988
3989 case WLAN_FSTYPE_REASSOCRESP:
3990 // Frame Clase = 2
3991 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
Andres More4e9b5e22013-02-12 20:36:30 -05003992 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
Forest Bond92b96792009-06-13 07:38:31 -04003993 break;
3994
3995 case WLAN_FSTYPE_PROBEREQ:
3996 // Frame Clase = 0
3997 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
3998 s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
3999 break;
4000
4001 case WLAN_FSTYPE_PROBERESP:
4002 // Frame Clase = 0
4003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
4004
4005 s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
4006 break;
4007
4008 case WLAN_FSTYPE_BEACON:
4009 // Frame Clase = 0
4010 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
4011 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
Andres More4e9b5e22013-02-12 20:36:30 -05004012 bInScan = true;
Joe Perches9fc86022011-04-10 14:31:32 -07004013 }
Forest Bond92b96792009-06-13 07:38:31 -04004014 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4015 break;
4016
4017 case WLAN_FSTYPE_ATIM:
4018 // Frame Clase = 1
4019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
4020 break;
4021
4022 case WLAN_FSTYPE_DISASSOC:
4023 // Frame Clase = 2
4024 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
4025 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
4026 (eNodeState < NODE_AUTH)) {
4027 // send deauth notification
4028 // reason = (6) class 2 received from nonauth sta
4029 vMgrDeAuthenBeginSta(pDevice,
4030 pMgmt,
4031 pRxPacket->p80211Header->sA3.abyAddr2,
4032 (6),
4033 &Status
4034 );
4035 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
4036 }
4037 s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
4038 break;
4039
4040 case WLAN_FSTYPE_AUTHEN:
4041 // Frame Clase = 1
4042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx authen\n");
4043 s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
4044 break;
4045
4046 case WLAN_FSTYPE_DEAUTHEN:
4047 // Frame Clase = 1
4048 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
4049 s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
4050 break;
4051
4052 default:
4053 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
4054 }
4055
4056 return;
4057}
4058
Forest Bond92b96792009-06-13 07:38:31 -04004059/*+
4060 *
4061 * Routine Description:
4062 *
4063 *
4064 * Prepare beacon to send
4065 *
4066 * Return Value:
Andres More4e9b5e22013-02-12 20:36:30 -05004067 * true if success; false if failed.
Forest Bond92b96792009-06-13 07:38:31 -04004068 *
4069-*/
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004070int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
4071 struct vnt_manager *pMgmt)
Forest Bond92b96792009-06-13 07:38:31 -04004072{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004073 struct vnt_tx_mgmt *pTxPacket;
Forest Bond92b96792009-06-13 07:38:31 -04004074
Andres Moree269fc22013-02-12 20:36:29 -05004075// pDevice->bBeaconBufReady = false;
Forest Bond92b96792009-06-13 07:38:31 -04004076 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
4077 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4078 }
4079 else {
4080 pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
4081 }
4082 pTxPacket = s_MgrMakeBeacon
4083 (
4084 pDevice,
4085 pMgmt,
4086 pMgmt->wCurrCapInfo,
4087 pMgmt->wCurrBeaconPeriod,
4088 pMgmt->uCurrChannel,
4089 pMgmt->wCurrATIMWindow, //0,
4090 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
Andres Moreb902fbf2013-02-25 20:32:51 -05004091 (u8 *)pMgmt->abyCurrBSSID,
Forest Bond92b96792009-06-13 07:38:31 -04004092 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4093 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
4094 );
4095
4096 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4097 (pMgmt->abyCurrBSSID[0] == 0))
Andres Moree269fc22013-02-12 20:36:29 -05004098 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004099
4100 csBeacon_xmit(pDevice, pTxPacket);
4101 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
4102
Andres More4e9b5e22013-02-12 20:36:30 -05004103 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004104}
4105
Forest Bond92b96792009-06-13 07:38:31 -04004106/*+
4107 *
4108 * Routine Description:
4109 *
4110 * Log a warning message based on the contents of the Status
4111 * Code field of an 802.11 management frame. Defines are
4112 * derived from 802.11-1997 SPEC.
4113 *
4114 * Return Value:
4115 * none.
4116 *
4117-*/
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004118static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus)
Forest Bond92b96792009-06-13 07:38:31 -04004119{
4120 switch( wStatus ){
4121 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
4122 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
4123 break;
4124 case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
4125 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
4126 break;
4127 case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
4128 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
4129 break;
4130 case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
4131 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
4132 break;
4133 case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
4134 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
4135 break;
4136 case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
4137 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
4138 break;
4139 case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
4140 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge failure.\n");
4141 break;
4142 case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
4143 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
4144 break;
4145 case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
4146 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
4147 break;
4148 case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
4149 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
4150 break;
4151 case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
4152 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
4153 break;
4154 case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
4155 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
4156 break;
4157 case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
4158 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
4159 break;
4160 default:
4161 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
4162 break;
4163 }
4164}
4165
Forest Bond92b96792009-06-13 07:38:31 -04004166/*
4167 *
4168 * Description:
4169 * Add BSSID in PMKID Candidate list.
4170 *
4171 * Parameters:
4172 * In:
4173 * hDeviceContext - device structure point
4174 * pbyBSSID - BSSID address for adding
4175 * wRSNCap - BSS's RSN capability
4176 * Out:
4177 * none
4178 *
4179 * Return Value: none.
4180 *
4181-*/
Andres More0cbd8d92010-05-06 20:34:29 -03004182
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004183int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID,
4184 PSRSNCapObject psRSNCapObj)
Forest Bond92b96792009-06-13 07:38:31 -04004185{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004186 PPMKID_CANDIDATE pCandidateList;
4187 int ii = 0;
Forest Bond92b96792009-06-13 07:38:31 -04004188
4189 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4190
4191 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
Andres Moree269fc22013-02-12 20:36:29 -05004192 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004193
4194 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
Andres Moree269fc22013-02-12 20:36:29 -05004195 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004196
Forest Bond92b96792009-06-13 07:38:31 -04004197 // Update Old Candidate
4198 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
Andres More9a0e7562010-04-13 21:54:48 -03004199 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4200 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
Andres More4e9b5e22013-02-12 20:36:30 -05004201 if ((psRSNCapObj->bRSNCapExist == true)
Andres More9a0e7562010-04-13 21:54:48 -03004202 && (psRSNCapObj->wRSNCap & BIT0)) {
4203 pCandidateList->Flags |=
4204 NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4205 } else {
4206 pCandidateList->Flags &=
4207 ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4208 }
Andres More4e9b5e22013-02-12 20:36:30 -05004209 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004210 }
4211 }
4212
4213 // New Candidate
4214 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
Andres More4e9b5e22013-02-12 20:36:30 -05004215 if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
Forest Bond92b96792009-06-13 07:38:31 -04004216 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4217 } else {
4218 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4219 }
Andres More9a0e7562010-04-13 21:54:48 -03004220 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04004221 pDevice->gsPMKIDCandidate.NumCandidates++;
4222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
Andres More4e9b5e22013-02-12 20:36:30 -05004223 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004224}
4225
4226/*
4227 *
4228 * Description:
4229 * Flush PMKID Candidate list.
4230 *
4231 * Parameters:
4232 * In:
4233 * hDeviceContext - device structure point
4234 * Out:
4235 * none
4236 *
4237 * Return Value: none.
4238 *
4239-*/
Andres More0cbd8d92010-05-06 20:34:29 -03004240
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004241void vFlush_PMKID_Candidate(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -04004242{
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004243 if (pDevice == NULL)
4244 return;
Forest Bond92b96792009-06-13 07:38:31 -04004245
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004246 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
Forest Bond92b96792009-06-13 07:38:31 -04004247
Malcolm Priestley78f41c92012-12-10 22:03:56 +00004248 return;
Forest Bond92b96792009-06-13 07:38:31 -04004249}
4250
Andres Moredfdcc422013-02-12 20:36:28 -05004251static bool
Forest Bond92b96792009-06-13 07:38:31 -04004252s_bCipherMatch (
Andres More592ccfe2010-04-17 12:07:42 -03004253 PKnownBSS pBSSNode,
4254 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
Andres Moreb902fbf2013-02-25 20:32:51 -05004255 u8 * pbyCCSPK,
4256 u8 * pbyCCSGK
Forest Bond92b96792009-06-13 07:38:31 -04004257 )
4258{
Andres Moreb902fbf2013-02-25 20:32:51 -05004259 u8 byMulticastCipher = KEY_CTL_INVALID;
4260 u8 byCipherMask = 0x00;
Forest Bond92b96792009-06-13 07:38:31 -04004261 int i;
4262
4263 if (pBSSNode == NULL)
Andres Moree269fc22013-02-12 20:36:29 -05004264 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004265
4266 // check cap. of BSS
4267 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4268 (EncStatus == Ndis802_11Encryption1Enabled)) {
4269 // default is WEP only
4270 byMulticastCipher = KEY_CTL_WEP;
4271 }
4272
4273 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
Andres More4e9b5e22013-02-12 20:36:30 -05004274 (pBSSNode->bWPA2Valid == true) &&
Andres More465711b2010-08-03 20:25:50 -03004275
Andres Morebd2bc4c2010-08-02 23:35:57 -03004276 ((EncStatus == Ndis802_11Encryption3Enabled) ||
4277 (EncStatus == Ndis802_11Encryption2Enabled))) {
Forest Bond92b96792009-06-13 07:38:31 -04004278 //WPA2
4279 // check Group Key Cipher
4280 if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
4281 (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
4282 byMulticastCipher = KEY_CTL_WEP;
4283 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
4284 byMulticastCipher = KEY_CTL_TKIP;
4285 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
4286 byMulticastCipher = KEY_CTL_CCMP;
4287 } else {
4288 byMulticastCipher = KEY_CTL_INVALID;
4289 }
4290
Andres More33d33e422010-05-19 23:50:00 -03004291 /* check Pairwise Key Cipher */
4292 for (i = 0; i < pBSSNode->wCSSPKCount; i++) {
4293 if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
4294 (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
4295 /* this should not happen as defined 802.11i */
4296 byCipherMask |= 0x01;
4297 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
4298 byCipherMask |= 0x02;
4299 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
4300 byCipherMask |= 0x04;
4301 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
4302 /* use group key only ignore all others */
4303 byCipherMask = 0;
4304 i = pBSSNode->wCSSPKCount;
4305 }
Forest Bond92b96792009-06-13 07:38:31 -04004306 }
4307
4308 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
Andres More4e9b5e22013-02-12 20:36:30 -05004309 (pBSSNode->bWPAValid == true) &&
Forest Bond92b96792009-06-13 07:38:31 -04004310 ((EncStatus == Ndis802_11Encryption2Enabled) || (EncStatus == Ndis802_11Encryption3Enabled))) {
4311 //WPA
4312 // check Group Key Cipher
4313 if ((pBSSNode->byGKType == WPA_WEP40) ||
4314 (pBSSNode->byGKType == WPA_WEP104)) {
4315 byMulticastCipher = KEY_CTL_WEP;
4316 } else if (pBSSNode->byGKType == WPA_TKIP) {
4317 byMulticastCipher = KEY_CTL_TKIP;
4318 } else if (pBSSNode->byGKType == WPA_AESCCMP) {
4319 byMulticastCipher = KEY_CTL_CCMP;
4320 } else {
4321 byMulticastCipher = KEY_CTL_INVALID;
4322 }
4323
Andres More33d33e422010-05-19 23:50:00 -03004324 /* check Pairwise Key Cipher */
4325 for (i = 0; i < pBSSNode->wPKCount; i++) {
4326 if (pBSSNode->abyPKType[i] == WPA_TKIP) {
4327 byCipherMask |= 0x02;
4328 } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
4329 byCipherMask |= 0x04;
4330 } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
4331 /* use group key only ignore all others */
4332 byCipherMask = 0;
4333 i = pBSSNode->wPKCount;
4334 }
Forest Bond92b96792009-06-13 07:38:31 -04004335 }
4336 }
4337
4338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%d, %d, %d, %d, EncStatus:%d\n",
4339 byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
4340
4341 // mask our cap. with BSS
4342 if (EncStatus == Ndis802_11Encryption1Enabled) {
4343
4344 // For supporting Cisco migration mode, don't care pairwise key cipher
4345 //if ((byMulticastCipher == KEY_CTL_WEP) &&
4346 // (byCipherMask == 0)) {
4347 if ((byMulticastCipher == KEY_CTL_WEP) &&
4348 (byCipherMask == 0)) {
4349 *pbyCCSGK = KEY_CTL_WEP;
4350 *pbyCCSPK = KEY_CTL_NONE;
Andres More4e9b5e22013-02-12 20:36:30 -05004351 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004352 } else {
Andres Moree269fc22013-02-12 20:36:29 -05004353 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004354 }
4355
4356 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
4357 if ((byMulticastCipher == KEY_CTL_TKIP) &&
4358 (byCipherMask == 0)) {
4359 *pbyCCSGK = KEY_CTL_TKIP;
4360 *pbyCCSPK = KEY_CTL_NONE;
Andres More4e9b5e22013-02-12 20:36:30 -05004361 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004362 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4363 ((byCipherMask & 0x02) != 0)) {
4364 *pbyCCSGK = KEY_CTL_WEP;
4365 *pbyCCSPK = KEY_CTL_TKIP;
Andres More4e9b5e22013-02-12 20:36:30 -05004366 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004367 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4368 ((byCipherMask & 0x02) != 0)) {
4369 *pbyCCSGK = KEY_CTL_TKIP;
4370 *pbyCCSPK = KEY_CTL_TKIP;
Andres More4e9b5e22013-02-12 20:36:30 -05004371 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004372 } else {
Andres Moree269fc22013-02-12 20:36:29 -05004373 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004374 }
4375 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
4376 if ((byMulticastCipher == KEY_CTL_CCMP) &&
4377 (byCipherMask == 0)) {
4378 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
Andres Moree269fc22013-02-12 20:36:29 -05004379 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004380 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4381 ((byCipherMask & 0x04) != 0)) {
4382 *pbyCCSGK = KEY_CTL_WEP;
4383 *pbyCCSPK = KEY_CTL_CCMP;
Andres More4e9b5e22013-02-12 20:36:30 -05004384 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004385 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4386 ((byCipherMask & 0x04) != 0)) {
4387 *pbyCCSGK = KEY_CTL_TKIP;
4388 *pbyCCSPK = KEY_CTL_CCMP;
Andres More4e9b5e22013-02-12 20:36:30 -05004389 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004390 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
4391 ((byCipherMask & 0x04) != 0)) {
4392 *pbyCCSGK = KEY_CTL_CCMP;
4393 *pbyCCSPK = KEY_CTL_CCMP;
Andres More4e9b5e22013-02-12 20:36:30 -05004394 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004395 } else {
Andres Moree269fc22013-02-12 20:36:29 -05004396 return false;
Forest Bond92b96792009-06-13 07:38:31 -04004397 }
4398 }
Andres More4e9b5e22013-02-12 20:36:30 -05004399 return true;
Forest Bond92b96792009-06-13 07:38:31 -04004400}
4401