blob: 6367684bd2180f035eb03ea9f3d6281ba749cabb [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -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 * File: bssdb.c
20 *
21 * Purpose: Handles the Basic Service Set & Node Database functions
22 *
23 * Functions:
24 * BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
25 * BSSvClearBSSList - Clear BSS List
26 * BSSbInsertToBSSList - Insert a BSS set into known BSS list
27 * BSSbUpdateToBSSList - Update BSS set in known BSS list
28 * BSSDBbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
29 * BSSvCreateOneNode - Allocate an Node for Node DB
30 * BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
31 * BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
32 * BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
33 *
34 * Revision History:
35 *
36 * Author: Lyndon Chen
37 *
38 * Date: July 17, 2002
39 *
40 */
41
Forest Bond5449c682009-04-25 10:30:44 -040042#include "ttype.h"
Forest Bond5449c682009-04-25 10:30:44 -040043#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040044#include "tether.h"
Forest Bond5449c682009-04-25 10:30:44 -040045#include "device.h"
Forest Bond5449c682009-04-25 10:30:44 -040046#include "80211hdr.h"
Forest Bond5449c682009-04-25 10:30:44 -040047#include "bssdb.h"
Forest Bond5449c682009-04-25 10:30:44 -040048#include "wmgr.h"
Forest Bond5449c682009-04-25 10:30:44 -040049#include "datarate.h"
Forest Bond5449c682009-04-25 10:30:44 -040050#include "desc.h"
Forest Bond5449c682009-04-25 10:30:44 -040051#include "wcmd.h"
Forest Bond5449c682009-04-25 10:30:44 -040052#include "wpa.h"
Forest Bond5449c682009-04-25 10:30:44 -040053#include "baseband.h"
Forest Bond5449c682009-04-25 10:30:44 -040054#include "rf.h"
Forest Bond5449c682009-04-25 10:30:44 -040055#include "card.h"
Charles Clément79566eb2010-06-21 10:39:51 -070056#include "channel.h"
Forest Bond5449c682009-04-25 10:30:44 -040057#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040058#include "wpa2.h"
Forest Bond5449c682009-04-25 10:30:44 -040059#include "iowpa.h"
Forest Bond5449c682009-04-25 10:30:44 -040060
Forest Bond5449c682009-04-25 10:30:44 -040061/*--------------------- Static Definitions -------------------------*/
62
Forest Bond5449c682009-04-25 10:30:44 -040063/*--------------------- Static Classes ----------------------------*/
64
65/*--------------------- Static Variables --------------------------*/
Joe Perchese1c77572013-03-18 10:44:39 -070066static int msglevel = MSG_LEVEL_INFO;
Forest Bond5449c682009-04-25 10:30:44 -040067
Guillaume Clement9e4c5c22014-07-22 22:08:28 +020068static const unsigned short awHWRetry0[5][5] = {
Joe Perchese1c77572013-03-18 10:44:39 -070069 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
70 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
71 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
72 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
73 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
74};
Guillaume Clement9e4c5c22014-07-22 22:08:28 +020075static const unsigned short awHWRetry1[5][5] = {
Joe Perchese1c77572013-03-18 10:44:39 -070076 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
77 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
78 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
79 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
80 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
81};
Forest Bond5449c682009-04-25 10:30:44 -040082
Forest Bond5449c682009-04-25 10:30:44 -040083/*--------------------- Static Functions --------------------------*/
84
Charles Clément6b35b7b2010-05-07 12:30:19 -070085void s_vCheckSensitivity(
Joe Perchese1c77572013-03-18 10:44:39 -070086 void *hDeviceContext
87);
Forest Bond5449c682009-04-25 10:30:44 -040088
89#ifdef Calcu_LinkQual
Charles Clément6b35b7b2010-05-07 12:30:19 -070090void s_uCalculateLinkQual(
Joe Perchese1c77572013-03-18 10:44:39 -070091 void *hDeviceContext
92);
Forest Bond5449c682009-04-25 10:30:44 -040093#endif
94
Charles Clément6b35b7b2010-05-07 12:30:19 -070095void s_vCheckPreEDThreshold(
Joe Perchese1c77572013-03-18 10:44:39 -070096 void *hDeviceContext
97);
Forest Bond5449c682009-04-25 10:30:44 -040098/*--------------------- Export Variables --------------------------*/
99
Forest Bond5449c682009-04-25 10:30:44 -0400100/*--------------------- Export Functions --------------------------*/
101
Forest Bond5449c682009-04-25 10:30:44 -0400102/*+
103 *
104 * Routine Description:
105 * Search known BSS list for Desire SSID or BSSID.
106 *
107 * Return Value:
108 * PTR to KnownBSS or NULL
109 *
Joe Perchese1c77572013-03-18 10:44:39 -0700110 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400111
112PKnownBSS
113BSSpSearchBSSList(
Joe Perchese1c77572013-03-18 10:44:39 -0700114 void *hDeviceContext,
115 unsigned char *pbyDesireBSSID,
116 unsigned char *pbyDesireSSID,
117 CARD_PHY_TYPE ePhyType
118)
Forest Bond5449c682009-04-25 10:30:44 -0400119{
Joe Perchese1c77572013-03-18 10:44:39 -0700120 PSDevice pDevice = (PSDevice)hDeviceContext;
121 PSMgmtObject pMgmt = pDevice->pMgmt;
122 unsigned char *pbyBSSID = NULL;
123 PWLAN_IE_SSID pSSID = NULL;
124 PKnownBSS pCurrBSS = NULL;
125 PKnownBSS pSelect = NULL;
126 unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
127 unsigned int ii = 0;
Charles Clémentb6e95cd2010-06-02 09:52:01 -0700128
Joe Perchese1c77572013-03-18 10:44:39 -0700129 if (pbyDesireBSSID != NULL) {
Andy Shevchenko075fb4b2012-07-06 18:28:16 +0300130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
131 "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
Joe Perchese1c77572013-03-18 10:44:39 -0700132 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
Teodora Baluta347a0472013-11-09 01:00:01 +0200133 (memcmp(pbyDesireBSSID, ZeroBSSID, 6) != 0))
Joe Perchese1c77572013-03-18 10:44:39 -0700134 pbyBSSID = pbyDesireBSSID;
Joe Perchese1c77572013-03-18 10:44:39 -0700135 }
136 if (pbyDesireSSID != NULL) {
Teodora Baluta347a0472013-11-09 01:00:01 +0200137 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0)
Joe Perchese1c77572013-03-18 10:44:39 -0700138 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
Joe Perchese1c77572013-03-18 10:44:39 -0700139 }
Forest Bond5449c682009-04-25 10:30:44 -0400140
Joe Perchese1c77572013-03-18 10:44:39 -0700141 if (pbyBSSID != NULL) {
Teodora Baluta38395642013-11-09 01:00:00 +0200142 /* match BSSID first */
Joe Perchese1c77572013-03-18 10:44:39 -0700143 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
144 pCurrBSS = &(pMgmt->sBSSList[ii]);
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200145 if (!pDevice->bLinkPass)
Teodora Balutab4f66ad2013-11-09 01:00:02 +0200146 pCurrBSS->bSelected = false;
Joe Perchese1c77572013-03-18 10:44:39 -0700147 if ((pCurrBSS->bActive) &&
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200148 (!pCurrBSS->bSelected)) {
Joe Perches83294192013-09-01 12:15:47 -0700149 if (ether_addr_equal(pCurrBSS->abyBSSID,
150 pbyBSSID)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700151 if (pSSID != NULL) {
Teodora Baluta38395642013-11-09 01:00:00 +0200152 /* compare ssid */
Joe Perchese1c77572013-03-18 10:44:39 -0700153 if (!memcmp(pSSID->abySSID,
154 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
155 pSSID->len)) {
156 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
157 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
158 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
159) {
160 pCurrBSS->bSelected = true;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700161 return pCurrBSS;
Joe Perchese1c77572013-03-18 10:44:39 -0700162 }
163 }
164 } else {
165 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
166 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
167 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
168) {
169 pCurrBSS->bSelected = true;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700170 return pCurrBSS;
Joe Perchese1c77572013-03-18 10:44:39 -0700171 }
172 }
173 }
174 }
175 }
176 } else {
Teodora Baluta38395642013-11-09 01:00:00 +0200177 /* ignore BSSID */
Joe Perchese1c77572013-03-18 10:44:39 -0700178 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
179 pCurrBSS = &(pMgmt->sBSSList[ii]);
Teodora Baluta38395642013-11-09 01:00:00 +0200180 /* 2007-0721-01<Add>by MikeLiu */
Joe Perchese1c77572013-03-18 10:44:39 -0700181 pCurrBSS->bSelected = false;
182 if (pCurrBSS->bActive) {
Joe Perchese1c77572013-03-18 10:44:39 -0700183 if (pSSID != NULL) {
Teodora Baluta38395642013-11-09 01:00:00 +0200184 /* matched SSID */
Joe Perchese1c77572013-03-18 10:44:39 -0700185 if (!!memcmp(pSSID->abySSID,
186 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
187 pSSID->len) ||
188 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200189 /* SSID not match skip this BSS */
Joe Perchese1c77572013-03-18 10:44:39 -0700190 continue;
191 }
192 }
193 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
194 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
195) {
Teodora Baluta38395642013-11-09 01:00:00 +0200196 /* Type not match skip this BSS */
Joe Perchese1c77572013-03-18 10:44:39 -0700197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
198 continue;
199 }
Forest Bond5449c682009-04-25 10:30:44 -0400200
Joe Perchese1c77572013-03-18 10:44:39 -0700201 if (ePhyType != PHY_TYPE_AUTO) {
202 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
203 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
Teodora Baluta38395642013-11-09 01:00:00 +0200204 /* PhyType not match skip this BSS */
Joe Perchese1c77572013-03-18 10:44:39 -0700205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
206 continue;
207 }
208 }
Teodora Baluta38395642013-11-09 01:00:00 +0200209
Joe Perchese1c77572013-03-18 10:44:39 -0700210 if (pSelect == NULL) {
211 pSelect = pCurrBSS;
212 } else {
Teodora Baluta38395642013-11-09 01:00:00 +0200213 /* compare RSSI, select signal strong one */
Teodora Baluta347a0472013-11-09 01:00:01 +0200214 if (pCurrBSS->uRSSI < pSelect->uRSSI)
Joe Perchese1c77572013-03-18 10:44:39 -0700215 pSelect = pCurrBSS;
Joe Perchese1c77572013-03-18 10:44:39 -0700216 }
217 }
218 }
219 if (pSelect != NULL) {
220 pSelect->bSelected = true;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700221 return pSelect;
Joe Perchese1c77572013-03-18 10:44:39 -0700222 }
223 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700224 return NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400225}
226
Forest Bond5449c682009-04-25 10:30:44 -0400227/*+
228 *
229 * Routine Description:
230 * Clear BSS List
231 *
232 * Return Value:
233 * None.
234 *
Joe Perchese1c77572013-03-18 10:44:39 -0700235 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400236
Charles Clément6b35b7b2010-05-07 12:30:19 -0700237void
Forest Bond5449c682009-04-25 10:30:44 -0400238BSSvClearBSSList(
Joe Perchese1c77572013-03-18 10:44:39 -0700239 void *hDeviceContext,
240 bool bKeepCurrBSSID
241)
Forest Bond5449c682009-04-25 10:30:44 -0400242{
Joe Perchese1c77572013-03-18 10:44:39 -0700243 PSDevice pDevice = (PSDevice)hDeviceContext;
244 PSMgmtObject pMgmt = pDevice->pMgmt;
245 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400246
Joe Perchese1c77572013-03-18 10:44:39 -0700247 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
248 if (bKeepCurrBSSID) {
249 if (pMgmt->sBSSList[ii].bActive &&
Joe Perches83294192013-09-01 12:15:47 -0700250 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
251 pMgmt->abyCurrBSSID)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700252 continue;
253 }
254 }
Forest Bond5449c682009-04-25 10:30:44 -0400255
Joe Perchese1c77572013-03-18 10:44:39 -0700256 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
257 pMgmt->sBSSList[ii].uClearCount++;
258 continue;
259 }
Forest Bond5449c682009-04-25 10:30:44 -0400260
Joe Perchese1c77572013-03-18 10:44:39 -0700261 pMgmt->sBSSList[ii].bActive = false;
262 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
263 }
264 BSSvClearAnyBSSJoinRecord(pDevice);
Forest Bond5449c682009-04-25 10:30:44 -0400265}
266
Forest Bond5449c682009-04-25 10:30:44 -0400267/*+
268 *
269 * Routine Description:
270 * search BSS list by BSSID & SSID if matched
271 *
272 * Return Value:
Charles Clément1b120682010-08-01 17:15:48 +0200273 * true if found.
Forest Bond5449c682009-04-25 10:30:44 -0400274 *
Joe Perchese1c77572013-03-18 10:44:39 -0700275 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400276PKnownBSS
277BSSpAddrIsInBSSList(
Joe Perchese1c77572013-03-18 10:44:39 -0700278 void *hDeviceContext,
279 unsigned char *abyBSSID,
280 PWLAN_IE_SSID pSSID
281)
Forest Bond5449c682009-04-25 10:30:44 -0400282{
Joe Perchese1c77572013-03-18 10:44:39 -0700283 PSDevice pDevice = (PSDevice)hDeviceContext;
284 PSMgmtObject pMgmt = pDevice->pMgmt;
285 PKnownBSS pBSSList = NULL;
286 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400287
Joe Perchese1c77572013-03-18 10:44:39 -0700288 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
289 pBSSList = &(pMgmt->sBSSList[ii]);
290 if (pBSSList->bActive) {
Joe Perches83294192013-09-01 12:15:47 -0700291 if (ether_addr_equal(pBSSList->abyBSSID, abyBSSID)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700292 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len) {
293 if (memcmp(pSSID->abySSID,
294 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
295 pSSID->len) == 0)
296 return pBSSList;
297 }
298 }
299 }
300 }
Forest Bond5449c682009-04-25 10:30:44 -0400301
Joe Perchese1c77572013-03-18 10:44:39 -0700302 return NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400303};
304
Forest Bond5449c682009-04-25 10:30:44 -0400305/*+
306 *
307 * Routine Description:
308 * Insert a BSS set into known BSS list
309 *
310 * Return Value:
Charles Clément1b120682010-08-01 17:15:48 +0200311 * true if success.
Forest Bond5449c682009-04-25 10:30:44 -0400312 *
Joe Perchese1c77572013-03-18 10:44:39 -0700313 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400314
Charles Clément7b6a0012010-08-01 17:15:50 +0200315bool
Joe Perchese1c77572013-03-18 10:44:39 -0700316BSSbInsertToBSSList(
317 void *hDeviceContext,
318 unsigned char *abyBSSIDAddr,
319 QWORD qwTimestamp,
320 unsigned short wBeaconInterval,
321 unsigned short wCapInfo,
322 unsigned char byCurrChannel,
323 PWLAN_IE_SSID pSSID,
324 PWLAN_IE_SUPP_RATES pSuppRates,
325 PWLAN_IE_SUPP_RATES pExtSuppRates,
326 PERPObject psERP,
327 PWLAN_IE_RSN pRSN,
328 PWLAN_IE_RSN_EXT pRSNWPA,
329 PWLAN_IE_COUNTRY pIE_Country,
330 PWLAN_IE_QUIET pIE_Quiet,
331 unsigned int uIELength,
332 unsigned char *pbyIEs,
333 void *pRxPacketContext
334)
Forest Bond5449c682009-04-25 10:30:44 -0400335{
Joe Perchese1c77572013-03-18 10:44:39 -0700336 PSDevice pDevice = (PSDevice)hDeviceContext;
337 PSMgmtObject pMgmt = pDevice->pMgmt;
338 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
339 PKnownBSS pBSSList = NULL;
340 unsigned int ii;
341 bool bParsingQuiet = false;
342 PWLAN_IE_QUIET pQuiet = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400343
Joe Perchese1c77572013-03-18 10:44:39 -0700344 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
Forest Bond5449c682009-04-25 10:30:44 -0400345
Joe Perchese1c77572013-03-18 10:44:39 -0700346 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
347 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
348 if (!pBSSList->bActive)
349 break;
350 }
Forest Bond5449c682009-04-25 10:30:44 -0400351
Joe Perchese1c77572013-03-18 10:44:39 -0700352 if (ii == MAX_BSS_NUM) {
353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
354 return false;
355 }
Teodora Baluta38395642013-11-09 01:00:00 +0200356 /* save the BSS info */
Joe Perchese1c77572013-03-18 10:44:39 -0700357 pBSSList->bActive = true;
358 memcpy(pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
359 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
360 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
361 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
362 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
363 pBSSList->uClearCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400364
Joe Perchese1c77572013-03-18 10:44:39 -0700365 if (pSSID->len > WLAN_SSID_MAXLEN)
366 pSSID->len = WLAN_SSID_MAXLEN;
367 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -0400368
Joe Perchese1c77572013-03-18 10:44:39 -0700369 pBSSList->uChannel = byCurrChannel;
Forest Bond5449c682009-04-25 10:30:44 -0400370
Joe Perchese1c77572013-03-18 10:44:39 -0700371 if (pSuppRates->len > WLAN_RATES_MAXLEN)
372 pSuppRates->len = WLAN_RATES_MAXLEN;
373 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -0400374
Joe Perchese1c77572013-03-18 10:44:39 -0700375 if (pExtSuppRates != NULL) {
376 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
377 pExtSuppRates->len = WLAN_RATES_MAXLEN;
378 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
Forest Bond5449c682009-04-25 10:30:44 -0400380
Joe Perchese1c77572013-03-18 10:44:39 -0700381 } else {
382 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
383 }
384 pBSSList->sERP.byERP = psERP->byERP;
385 pBSSList->sERP.bERPExist = psERP->bERPExist;
Forest Bond5449c682009-04-25 10:30:44 -0400386
Teodora Baluta38395642013-11-09 01:00:00 +0200387 /* check if BSS is 802.11a/b/g */
Joe Perchese1c77572013-03-18 10:44:39 -0700388 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
389 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
390 } else {
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200391 if (pBSSList->sERP.bERPExist)
Joe Perchese1c77572013-03-18 10:44:39 -0700392 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
Teodora Baluta347a0472013-11-09 01:00:01 +0200393 else
Joe Perchese1c77572013-03-18 10:44:39 -0700394 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
Joe Perchese1c77572013-03-18 10:44:39 -0700395 }
Forest Bond5449c682009-04-25 10:30:44 -0400396
Joe Perchese1c77572013-03-18 10:44:39 -0700397 pBSSList->byRxRate = pRxPacket->byRxRate;
398 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
399 pBSSList->uRSSI = pRxPacket->uRSSI;
400 pBSSList->bySQ = pRxPacket->bySQ;
Forest Bond5449c682009-04-25 10:30:44 -0400401
Joe Perchese1c77572013-03-18 10:44:39 -0700402 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
403 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200404 /* assoc with BSS */
Teodora Baluta347a0472013-11-09 01:00:01 +0200405 if (pBSSList == pMgmt->pCurrBSS)
Joe Perchese1c77572013-03-18 10:44:39 -0700406 bParsingQuiet = true;
Joe Perchese1c77572013-03-18 10:44:39 -0700407 }
Forest Bond5449c682009-04-25 10:30:44 -0400408
Joe Perchese1c77572013-03-18 10:44:39 -0700409 WPA_ClearRSN(pBSSList);
Forest Bond5449c682009-04-25 10:30:44 -0400410
Joe Perchese1c77572013-03-18 10:44:39 -0700411 if (pRSNWPA != NULL) {
412 unsigned int uLen = pRSNWPA->len + 2;
Forest Bond5449c682009-04-25 10:30:44 -0400413
Joe Perchese1c77572013-03-18 10:44:39 -0700414 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
415 pBSSList->wWPALen = uLen;
416 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
417 WPA_ParseRSN(pBSSList, pRSNWPA);
418 }
419 }
Forest Bond5449c682009-04-25 10:30:44 -0400420
Joe Perchese1c77572013-03-18 10:44:39 -0700421 WPA2_ClearRSN(pBSSList);
Forest Bond5449c682009-04-25 10:30:44 -0400422
Joe Perchese1c77572013-03-18 10:44:39 -0700423 if (pRSN != NULL) {
424 unsigned int uLen = pRSN->len + 2;
Guillaume Clement6b711272014-07-25 01:06:16 +0200425
Joe Perchese1c77572013-03-18 10:44:39 -0700426 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
427 pBSSList->wRSNLen = uLen;
428 memcpy(pBSSList->byRSNIE, pRSN, uLen);
429 WPA2vParseRSN(pBSSList, pRSN);
430 }
431 }
Forest Bond5449c682009-04-25 10:30:44 -0400432
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200433 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || pBSSList->bWPA2Valid) {
Joe Perchese1c77572013-03-18 10:44:39 -0700434 PSKeyItem pTransmitKey = NULL;
435 bool bIs802_1x = false;
Forest Bond5449c682009-04-25 10:30:44 -0400436
Joe Perchese1c77572013-03-18 10:44:39 -0700437 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii++) {
438 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
439 bIs802_1x = true;
440 break;
441 }
442 }
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200443 if (bIs802_1x && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
Joe Perchese1c77572013-03-18 10:44:39 -0700444 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
Joe Perchese1c77572013-03-18 10:44:39 -0700445 bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
Forest Bond5449c682009-04-25 10:30:44 -0400446
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200447 if (pDevice->bLinkPass && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
448 if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) ||
449 KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700450 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
451 pDevice->gsPMKIDCandidate.Version = 1;
Forest Bond5449c682009-04-25 10:30:44 -0400452
Joe Perchese1c77572013-03-18 10:44:39 -0700453 }
Forest Bond5449c682009-04-25 10:30:44 -0400454
Joe Perchese1c77572013-03-18 10:44:39 -0700455 }
456 }
457 }
Forest Bond5449c682009-04-25 10:30:44 -0400458
Joe Perchese1c77572013-03-18 10:44:39 -0700459 if (pDevice->bUpdateBBVGA) {
Teodora Baluta38395642013-11-09 01:00:00 +0200460 /* monitor if RSSI is too strong */
Joe Perchese1c77572013-03-18 10:44:39 -0700461 pBSSList->byRSSIStatCnt = 0;
462 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
463 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
464 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
465 pBSSList->ldBmAverage[ii] = 0;
466 }
Forest Bond5449c682009-04-25 10:30:44 -0400467
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200468 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
Joe Perchese1c77572013-03-18 10:44:39 -0700469 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
470 pIE_Country);
471 }
Forest Bond5449c682009-04-25 10:30:44 -0400472
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200473 if (bParsingQuiet && (pIE_Quiet != NULL)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700474 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
475 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200476 /* valid EID */
Joe Perchese1c77572013-03-18 10:44:39 -0700477 if (pQuiet == NULL) {
478 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
479 CARDbSetQuiet(pMgmt->pAdapter,
480 true,
481 pQuiet->byQuietCount,
482 pQuiet->byQuietPeriod,
483 *((unsigned short *)pQuiet->abyQuietDuration),
484 *((unsigned short *)pQuiet->abyQuietOffset)
485);
486 } else {
487 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
488 CARDbSetQuiet(pMgmt->pAdapter,
489 false,
490 pQuiet->byQuietCount,
491 pQuiet->byQuietPeriod,
492 *((unsigned short *)pQuiet->abyQuietDuration),
493 *((unsigned short *)pQuiet->abyQuietOffset)
494 );
495 }
496 }
497 }
Forest Bond5449c682009-04-25 10:30:44 -0400498
Guido Martínezbc5cf652014-04-19 16:45:00 -0300499 if (bParsingQuiet && (pQuiet != NULL))
Joe Perchese1c77572013-03-18 10:44:39 -0700500 CARDbStartQuiet(pMgmt->pAdapter);
Forest Bond5449c682009-04-25 10:30:44 -0400501
Joe Perchese1c77572013-03-18 10:44:39 -0700502 pBSSList->uIELength = uIELength;
503 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
504 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
505 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
Forest Bond5449c682009-04-25 10:30:44 -0400506
Joe Perchese1c77572013-03-18 10:44:39 -0700507 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400508}
509
Forest Bond5449c682009-04-25 10:30:44 -0400510/*+
511 *
512 * Routine Description:
513 * Update BSS set in known BSS list
514 *
515 * Return Value:
Charles Clément1b120682010-08-01 17:15:48 +0200516 * true if success.
Forest Bond5449c682009-04-25 10:30:44 -0400517 *
Joe Perchese1c77572013-03-18 10:44:39 -0700518 -*/
Teodora Baluta38395642013-11-09 01:00:00 +0200519/* TODO: input structure modify */
Forest Bond5449c682009-04-25 10:30:44 -0400520
Charles Clément7b6a0012010-08-01 17:15:50 +0200521bool
Joe Perchese1c77572013-03-18 10:44:39 -0700522BSSbUpdateToBSSList(
523 void *hDeviceContext,
524 QWORD qwTimestamp,
525 unsigned short wBeaconInterval,
526 unsigned short wCapInfo,
527 unsigned char byCurrChannel,
528 bool bChannelHit,
529 PWLAN_IE_SSID pSSID,
530 PWLAN_IE_SUPP_RATES pSuppRates,
531 PWLAN_IE_SUPP_RATES pExtSuppRates,
532 PERPObject psERP,
533 PWLAN_IE_RSN pRSN,
534 PWLAN_IE_RSN_EXT pRSNWPA,
535 PWLAN_IE_COUNTRY pIE_Country,
536 PWLAN_IE_QUIET pIE_Quiet,
537 PKnownBSS pBSSList,
538 unsigned int uIELength,
539 unsigned char *pbyIEs,
540 void *pRxPacketContext
541)
Forest Bond5449c682009-04-25 10:30:44 -0400542{
Joe Perchese1c77572013-03-18 10:44:39 -0700543 int ii;
544 PSDevice pDevice = (PSDevice)hDeviceContext;
545 PSMgmtObject pMgmt = pDevice->pMgmt;
546 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
547 long ldBm;
548 bool bParsingQuiet = false;
549 PWLAN_IE_QUIET pQuiet = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400550
Joe Perchese1c77572013-03-18 10:44:39 -0700551 if (pBSSList == NULL)
552 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400553
Joe Perchese1c77572013-03-18 10:44:39 -0700554 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
555 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
556 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
557 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
558 pBSSList->uClearCount = 0;
559 pBSSList->uChannel = byCurrChannel;
Forest Bond5449c682009-04-25 10:30:44 -0400560
Joe Perchese1c77572013-03-18 10:44:39 -0700561 if (pSSID->len > WLAN_SSID_MAXLEN)
562 pSSID->len = WLAN_SSID_MAXLEN;
Forest Bond5449c682009-04-25 10:30:44 -0400563
Joe Perchese1c77572013-03-18 10:44:39 -0700564 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
565 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
566 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -0400567
Teodora Baluta347a0472013-11-09 01:00:01 +0200568 if (pExtSuppRates != NULL)
Joe Perchese1c77572013-03-18 10:44:39 -0700569 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
Teodora Baluta347a0472013-11-09 01:00:01 +0200570 else
Joe Perchese1c77572013-03-18 10:44:39 -0700571 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
Joe Perchese1c77572013-03-18 10:44:39 -0700572 pBSSList->sERP.byERP = psERP->byERP;
573 pBSSList->sERP.bERPExist = psERP->bERPExist;
Forest Bond5449c682009-04-25 10:30:44 -0400574
Teodora Baluta38395642013-11-09 01:00:00 +0200575 /* check if BSS is 802.11a/b/g */
Joe Perchese1c77572013-03-18 10:44:39 -0700576 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
577 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
578 } else {
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200579 if (pBSSList->sERP.bERPExist)
Joe Perchese1c77572013-03-18 10:44:39 -0700580 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
Teodora Baluta347a0472013-11-09 01:00:01 +0200581 else
Joe Perchese1c77572013-03-18 10:44:39 -0700582 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
Joe Perchese1c77572013-03-18 10:44:39 -0700583 }
Forest Bond5449c682009-04-25 10:30:44 -0400584
Joe Perchese1c77572013-03-18 10:44:39 -0700585 pBSSList->byRxRate = pRxPacket->byRxRate;
586 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
587 if (bChannelHit)
588 pBSSList->uRSSI = pRxPacket->uRSSI;
589 pBSSList->bySQ = pRxPacket->bySQ;
Forest Bond5449c682009-04-25 10:30:44 -0400590
Joe Perchese1c77572013-03-18 10:44:39 -0700591 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
592 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200593 /* assoc with BSS */
Teodora Baluta347a0472013-11-09 01:00:01 +0200594 if (pBSSList == pMgmt->pCurrBSS)
Joe Perchese1c77572013-03-18 10:44:39 -0700595 bParsingQuiet = true;
Joe Perchese1c77572013-03-18 10:44:39 -0700596 }
Forest Bond5449c682009-04-25 10:30:44 -0400597
Teodora Baluta38395642013-11-09 01:00:00 +0200598 WPA_ClearRSN(pBSSList); /* mike update */
Forest Bond5449c682009-04-25 10:30:44 -0400599
Joe Perchese1c77572013-03-18 10:44:39 -0700600 if (pRSNWPA != NULL) {
601 unsigned int uLen = pRSNWPA->len + 2;
Guillaume Clement6b711272014-07-25 01:06:16 +0200602
Joe Perchese1c77572013-03-18 10:44:39 -0700603 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
604 pBSSList->wWPALen = uLen;
605 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
606 WPA_ParseRSN(pBSSList, pRSNWPA);
607 }
608 }
Forest Bond5449c682009-04-25 10:30:44 -0400609
Teodora Baluta38395642013-11-09 01:00:00 +0200610 WPA2_ClearRSN(pBSSList); /* mike update */
Forest Bond5449c682009-04-25 10:30:44 -0400611
Joe Perchese1c77572013-03-18 10:44:39 -0700612 if (pRSN != NULL) {
613 unsigned int uLen = pRSN->len + 2;
Guillaume Clement6b711272014-07-25 01:06:16 +0200614
Joe Perchese1c77572013-03-18 10:44:39 -0700615 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
616 pBSSList->wRSNLen = uLen;
617 memcpy(pBSSList->byRSNIE, pRSN, uLen);
618 WPA2vParseRSN(pBSSList, pRSN);
619 }
620 }
Forest Bond5449c682009-04-25 10:30:44 -0400621
Joe Perchese1c77572013-03-18 10:44:39 -0700622 if (pRxPacket->uRSSI != 0) {
623 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
Teodora Baluta38395642013-11-09 01:00:00 +0200624 /* monitor if RSSI is too strong */
Joe Perchese1c77572013-03-18 10:44:39 -0700625 pBSSList->byRSSIStatCnt++;
626 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
627 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
628 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
Teodora Baluta347a0472013-11-09 01:00:01 +0200629 if (pBSSList->ldBmAverage[ii] != 0)
Joe Perchese1c77572013-03-18 10:44:39 -0700630 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
Joe Perchese1c77572013-03-18 10:44:39 -0700631 }
632 }
Forest Bond5449c682009-04-25 10:30:44 -0400633
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200634 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
Joe Perchese1c77572013-03-18 10:44:39 -0700635 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
636 pIE_Country);
637 }
Forest Bond5449c682009-04-25 10:30:44 -0400638
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200639 if (bParsingQuiet && (pIE_Quiet != NULL)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700640 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
641 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200642 /* valid EID */
Joe Perchese1c77572013-03-18 10:44:39 -0700643 if (pQuiet == NULL) {
644 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
645 CARDbSetQuiet(pMgmt->pAdapter,
646 true,
647 pQuiet->byQuietCount,
648 pQuiet->byQuietPeriod,
649 *((unsigned short *)pQuiet->abyQuietDuration),
650 *((unsigned short *)pQuiet->abyQuietOffset)
651);
652 } else {
653 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
654 CARDbSetQuiet(pMgmt->pAdapter,
655 false,
656 pQuiet->byQuietCount,
657 pQuiet->byQuietPeriod,
658 *((unsigned short *)pQuiet->abyQuietDuration),
659 *((unsigned short *)pQuiet->abyQuietOffset)
660 );
661 }
662 }
663 }
Forest Bond5449c682009-04-25 10:30:44 -0400664
Guido Martínezbc5cf652014-04-19 16:45:00 -0300665 if (bParsingQuiet && (pQuiet != NULL))
Joe Perchese1c77572013-03-18 10:44:39 -0700666 CARDbStartQuiet(pMgmt->pAdapter);
Forest Bond5449c682009-04-25 10:30:44 -0400667
Joe Perchese1c77572013-03-18 10:44:39 -0700668 pBSSList->uIELength = uIELength;
669 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
670 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
671 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
Forest Bond5449c682009-04-25 10:30:44 -0400672
Joe Perchese1c77572013-03-18 10:44:39 -0700673 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400674}
675
Forest Bond5449c682009-04-25 10:30:44 -0400676/*+
677 *
678 * Routine Description:
679 * Search Node DB table to find the index of matched DstAddr
680 *
681 * Return Value:
682 * None
683 *
Joe Perchese1c77572013-03-18 10:44:39 -0700684 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400685
Charles Clément7b6a0012010-08-01 17:15:50 +0200686bool
Charles Clémentfe4f34b2010-06-25 10:48:53 -0700687BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
Joe Perchese1c77572013-03-18 10:44:39 -0700688 unsigned int *puNodeIndex)
Forest Bond5449c682009-04-25 10:30:44 -0400689{
Joe Perchese1c77572013-03-18 10:44:39 -0700690 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
691 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400692
Teodora Baluta38395642013-11-09 01:00:00 +0200693 /* Index = 0 reserved for AP Node */
Joe Perchese1c77572013-03-18 10:44:39 -0700694 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
695 if (pMgmt->sNodeDBTable[ii].bActive) {
Joe Perches83294192013-09-01 12:15:47 -0700696 if (ether_addr_equal(abyDstAddr,
697 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700698 *puNodeIndex = ii;
699 return true;
700 }
701 }
702 }
Forest Bond5449c682009-04-25 10:30:44 -0400703
Joe Perchese1c77572013-03-18 10:44:39 -0700704 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400705};
706
Forest Bond5449c682009-04-25 10:30:44 -0400707/*+
708 *
709 * Routine Description:
Justin P. Mattock789d1ae2012-08-20 08:43:13 -0700710 * Find an empty node and allocat it; if there is no empty node,
711 * then use the most inactive one.
Forest Bond5449c682009-04-25 10:30:44 -0400712 *
713 * Return Value:
714 * None
715 *
Joe Perchese1c77572013-03-18 10:44:39 -0700716 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700717void
Charles Clémentfe4f34b2010-06-25 10:48:53 -0700718BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
Forest Bond5449c682009-04-25 10:30:44 -0400719{
Joe Perchese1c77572013-03-18 10:44:39 -0700720 PSDevice pDevice = (PSDevice)hDeviceContext;
721 PSMgmtObject pMgmt = pDevice->pMgmt;
722 unsigned int ii;
723 unsigned int BigestCount = 0;
724 unsigned int SelectIndex;
725 struct sk_buff *skb;
Teodora Baluta38395642013-11-09 01:00:00 +0200726 /*
727 * Index = 0 reserved for AP Node (In STA mode)
728 * Index = 0 reserved for Broadcast/MultiCast (In AP mode)
729 */
Joe Perchese1c77572013-03-18 10:44:39 -0700730 SelectIndex = 1;
731 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
732 if (pMgmt->sNodeDBTable[ii].bActive) {
733 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
734 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
735 SelectIndex = ii;
736 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700737 } else {
Joe Perchese1c77572013-03-18 10:44:39 -0700738 break;
739 }
740 }
Forest Bond5449c682009-04-25 10:30:44 -0400741
Teodora Baluta38395642013-11-09 01:00:00 +0200742 /* if not found replace uInActiveCount is largest one */
Joe Perchese1c77572013-03-18 10:44:39 -0700743 if (ii == (MAX_NODE_NUM + 1)) {
744 *puNodeIndex = SelectIndex;
745 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
Teodora Baluta38395642013-11-09 01:00:00 +0200746 /* clear ps buffer */
Joe Perchese1c77572013-03-18 10:44:39 -0700747 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
748 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
749 dev_kfree_skb(skb);
750 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700751 } else {
Joe Perchese1c77572013-03-18 10:44:39 -0700752 *puNodeIndex = ii;
753 }
Forest Bond5449c682009-04-25 10:30:44 -0400754
Joe Perchese1c77572013-03-18 10:44:39 -0700755 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
756 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
757 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
Teodora Baluta38395642013-11-09 01:00:00 +0200758 /* for AP mode PS queue */
Joe Perchese1c77572013-03-18 10:44:39 -0700759 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
760 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
761 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
763 return;
Forest Bond5449c682009-04-25 10:30:44 -0400764};
765
Forest Bond5449c682009-04-25 10:30:44 -0400766/*+
767 *
768 * Routine Description:
769 * Remove Node by NodeIndex
770 *
771 *
772 * Return Value:
773 * None
774 *
Joe Perchese1c77572013-03-18 10:44:39 -0700775 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700776void
Forest Bond5449c682009-04-25 10:30:44 -0400777BSSvRemoveOneNode(
Joe Perchese1c77572013-03-18 10:44:39 -0700778 void *hDeviceContext,
779 unsigned int uNodeIndex
780)
Forest Bond5449c682009-04-25 10:30:44 -0400781{
Joe Perchese1c77572013-03-18 10:44:39 -0700782 PSDevice pDevice = (PSDevice)hDeviceContext;
783 PSMgmtObject pMgmt = pDevice->pMgmt;
784 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
785 struct sk_buff *skb;
Forest Bond5449c682009-04-25 10:30:44 -0400786
Joe Perchese1c77572013-03-18 10:44:39 -0700787 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
788 dev_kfree_skb(skb);
Teodora Baluta38395642013-11-09 01:00:00 +0200789 /* clear context */
Joe Perchese1c77572013-03-18 10:44:39 -0700790 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
Teodora Baluta38395642013-11-09 01:00:00 +0200791 /* clear tx bit map */
Joe Perchese1c77572013-03-18 10:44:39 -0700792 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
Forest Bond5449c682009-04-25 10:30:44 -0400793
Joe Perchese1c77572013-03-18 10:44:39 -0700794 return;
Forest Bond5449c682009-04-25 10:30:44 -0400795};
796/*+
797 *
798 * Routine Description:
799 * Update AP Node content in Index 0 of KnownNodeDB
800 *
801 *
802 * Return Value:
803 * None
804 *
Joe Perchese1c77572013-03-18 10:44:39 -0700805 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400806
Charles Clément6b35b7b2010-05-07 12:30:19 -0700807void
Forest Bond5449c682009-04-25 10:30:44 -0400808BSSvUpdateAPNode(
Joe Perchese1c77572013-03-18 10:44:39 -0700809 void *hDeviceContext,
810 unsigned short *pwCapInfo,
811 PWLAN_IE_SUPP_RATES pSuppRates,
812 PWLAN_IE_SUPP_RATES pExtSuppRates
813)
Forest Bond5449c682009-04-25 10:30:44 -0400814{
Joe Perchese1c77572013-03-18 10:44:39 -0700815 PSDevice pDevice = (PSDevice)hDeviceContext;
816 PSMgmtObject pMgmt = pDevice->pMgmt;
817 unsigned int uRateLen = WLAN_RATES_MAXLEN;
Forest Bond5449c682009-04-25 10:30:44 -0400818
Joe Perchese1c77572013-03-18 10:44:39 -0700819 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
Forest Bond5449c682009-04-25 10:30:44 -0400820
Joe Perchese1c77572013-03-18 10:44:39 -0700821 pMgmt->sNodeDBTable[0].bActive = true;
Teodora Baluta347a0472013-11-09 01:00:01 +0200822 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
Joe Perchese1c77572013-03-18 10:44:39 -0700823 uRateLen = WLAN_RATES_MAXLEN_11B;
Joe Perchese1c77572013-03-18 10:44:39 -0700824 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
825 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
826 uRateLen);
827 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
828 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
829 uRateLen);
830 RATEvParseMaxRate((void *)pDevice,
831 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
832 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
833 true,
834 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
835 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
836 &(pMgmt->sNodeDBTable[0].wSuppRate),
837 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
838 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
839);
840 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
841 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
842 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
843 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
Teodora Baluta18278772013-11-11 19:27:05 +0200844 netdev_dbg(pDevice->dev, "BSSvUpdateAPNode:MaxSuppRate is %d\n",
845 pMgmt->sNodeDBTable[0].wMaxSuppRate);
Teodora Baluta38395642013-11-09 01:00:00 +0200846 /* auto rate fallback function initiation */
Teodora Balutaa7772892013-11-11 19:27:06 +0200847 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->sNodeDBTable[0].wTxDataRate = %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
Forest Bond5449c682009-04-25 10:30:44 -0400848};
849
Forest Bond5449c682009-04-25 10:30:44 -0400850/*+
851 *
852 * Routine Description:
853 * Add Multicast Node content in Index 0 of KnownNodeDB
854 *
855 *
856 * Return Value:
857 * None
858 *
Joe Perchese1c77572013-03-18 10:44:39 -0700859 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400860
Charles Clément6b35b7b2010-05-07 12:30:19 -0700861void
Forest Bond5449c682009-04-25 10:30:44 -0400862BSSvAddMulticastNode(
Joe Perchese1c77572013-03-18 10:44:39 -0700863 void *hDeviceContext
864)
Forest Bond5449c682009-04-25 10:30:44 -0400865{
Joe Perchese1c77572013-03-18 10:44:39 -0700866 PSDevice pDevice = (PSDevice)hDeviceContext;
867 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -0400868
Joe Perchese1c77572013-03-18 10:44:39 -0700869 if (!pDevice->bEnableHostWEP)
870 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
871 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
872 pMgmt->sNodeDBTable[0].bActive = true;
873 pMgmt->sNodeDBTable[0].bPSEnable = false;
874 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
875 RATEvParseMaxRate((void *)pDevice,
876 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
877 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
878 true,
879 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
880 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
881 &(pMgmt->sNodeDBTable[0].wSuppRate),
882 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
883 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
884);
885 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
Teodora Baluta18278772013-11-11 19:27:05 +0200886 netdev_dbg(pDevice->dev,
887 "BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",
888 pMgmt->sNodeDBTable[0].wTxDataRate);
Joe Perchese1c77572013-03-18 10:44:39 -0700889 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
Forest Bond5449c682009-04-25 10:30:44 -0400890};
891
Forest Bond5449c682009-04-25 10:30:44 -0400892/*+
893 *
894 * Routine Description:
895 *
896 *
897 * Second call back function to update Node DB info & AP link status
898 *
899 *
900 * Return Value:
901 * none.
902 *
Joe Perchese1c77572013-03-18 10:44:39 -0700903 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700904void
Forest Bond5449c682009-04-25 10:30:44 -0400905BSSvSecondCallBack(
Joe Perchese1c77572013-03-18 10:44:39 -0700906 void *hDeviceContext
907)
Forest Bond5449c682009-04-25 10:30:44 -0400908{
Joe Perchese1c77572013-03-18 10:44:39 -0700909 PSDevice pDevice = (PSDevice)hDeviceContext;
910 PSMgmtObject pMgmt = pDevice->pMgmt;
911 unsigned int ii;
912 PWLAN_IE_SSID pItemSSID, pCurrSSID;
913 unsigned int uSleepySTACnt = 0;
914 unsigned int uNonShortSlotSTACnt = 0;
915 unsigned int uLongPreambleSTACnt = 0;
Teodora Baluta38395642013-11-09 01:00:00 +0200916 viawget_wpa_header *wpahdr; /* DavidWang */
Forest Bond5449c682009-04-25 10:30:44 -0400917
Joe Perchese1c77572013-03-18 10:44:39 -0700918 spin_lock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400919
Joe Perchese1c77572013-03-18 10:44:39 -0700920 pDevice->uAssocCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400921
Joe Perchese1c77572013-03-18 10:44:39 -0700922 pDevice->byERPFlag &=
923 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
Forest Bond5449c682009-04-25 10:30:44 -0400924
Joe Perchese1c77572013-03-18 10:44:39 -0700925 if (pDevice->wUseProtectCntDown > 0) {
926 pDevice->wUseProtectCntDown--;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700927 } else {
Teodora Baluta38395642013-11-09 01:00:00 +0200928 /* disable protect mode */
Joe Perchese1c77572013-03-18 10:44:39 -0700929 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
930 }
Forest Bond5449c682009-04-25 10:30:44 -0400931
Joe Perchese1c77572013-03-18 10:44:39 -0700932 {
933 pDevice->byReAssocCount++;
Teodora Baluta38395642013-11-09 01:00:00 +0200934 /* 10 sec timeout */
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200935 if ((pDevice->byReAssocCount > 10) && (!pDevice->bLinkPass)) {
Teodora Baluta18278772013-11-11 19:27:05 +0200936 netdev_info(pDevice->dev, "Re-association timeout!!!\n");
Joe Perchese1c77572013-03-18 10:44:39 -0700937 pDevice->byReAssocCount = 0;
938#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
Joe Perchese1c77572013-03-18 10:44:39 -0700939 {
940 union iwreq_data wrqu;
Guillaume Clement6b711272014-07-25 01:06:16 +0200941
Joe Perchese1c77572013-03-18 10:44:39 -0700942 memset(&wrqu, 0, sizeof(wrqu));
943 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
944 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
945 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
946 }
947#endif
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200948 } else if (pDevice->bLinkPass)
Joe Perchese1c77572013-03-18 10:44:39 -0700949 pDevice->byReAssocCount = 0;
950 }
Forest Bond5449c682009-04-25 10:30:44 -0400951
952#ifdef Calcu_LinkQual
Joe Perchese1c77572013-03-18 10:44:39 -0700953 s_uCalculateLinkQual((void *)pDevice);
Forest Bond5449c682009-04-25 10:30:44 -0400954#endif
955
Joe Perchese1c77572013-03-18 10:44:39 -0700956 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
Joe Perchese1c77572013-03-18 10:44:39 -0700957 if (pMgmt->sNodeDBTable[ii].bActive) {
Teodora Baluta38395642013-11-09 01:00:00 +0200958 /* increase in-activity counter */
Joe Perchese1c77572013-03-18 10:44:39 -0700959 pMgmt->sNodeDBTable[ii].uInActiveCount++;
Forest Bond5449c682009-04-25 10:30:44 -0400960
Joe Perchese1c77572013-03-18 10:44:39 -0700961 if (ii > 0) {
962 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
963 BSSvRemoveOneNode(pDevice, ii);
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
965 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
966 continue;
967 }
Forest Bond5449c682009-04-25 10:30:44 -0400968
Joe Perchese1c77572013-03-18 10:44:39 -0700969 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
Joe Perchese1c77572013-03-18 10:44:39 -0700970 pDevice->uAssocCount++;
Forest Bond5449c682009-04-25 10:30:44 -0400971
Teodora Baluta38395642013-11-09 01:00:00 +0200972 /* check if Non ERP exist */
Joe Perchese1c77572013-03-18 10:44:39 -0700973 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
974 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
975 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
976 uLongPreambleSTACnt++;
977 }
978 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
979 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
980 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
981 }
982 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
983 uNonShortSlotSTACnt++;
984 }
985 }
Forest Bond5449c682009-04-25 10:30:44 -0400986
Teodora Baluta38395642013-11-09 01:00:00 +0200987 /* check if any STA in PS mode */
Joe Perchese1c77572013-03-18 10:44:39 -0700988 if (pMgmt->sNodeDBTable[ii].bPSEnable)
989 uSleepySTACnt++;
Forest Bond5449c682009-04-25 10:30:44 -0400990
Joe Perchese1c77572013-03-18 10:44:39 -0700991 }
Forest Bond5449c682009-04-25 10:30:44 -0400992
Teodora Baluta38395642013-11-09 01:00:00 +0200993 /* rate fallback check */
Joe Perchese1c77572013-03-18 10:44:39 -0700994 if (!pDevice->bFixRate) {
Joe Perchese1c77572013-03-18 10:44:39 -0700995 if (ii > 0) {
Teodora Baluta38395642013-11-09 01:00:00 +0200996 /* ii = 0 for multicast node (AP & Adhoc) */
Joe Perchese1c77572013-03-18 10:44:39 -0700997 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700998 } else {
Teodora Baluta38395642013-11-09 01:00:00 +0200999 /* ii = 0 reserved for unicast AP node (Infra STA) */
Joe Perchese1c77572013-03-18 10:44:39 -07001000 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
Teodora Baluta18278772013-11-11 19:27:05 +02001001 netdev_dbg(pDevice->dev,
1002 "SecondCallback:Before:TxDataRate is %d\n",
1003 pMgmt->sNodeDBTable[0].wTxDataRate);
Joe Perchese1c77572013-03-18 10:44:39 -07001004 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
Teodora Baluta18278772013-11-11 19:27:05 +02001005 netdev_dbg(pDevice->dev,
1006 "SecondCallback:After:TxDataRate is %d\n",
1007 pMgmt->sNodeDBTable[0].wTxDataRate);
Forest Bond5449c682009-04-25 10:30:44 -04001008
Joe Perchese1c77572013-03-18 10:44:39 -07001009 }
1010
1011 }
1012
Teodora Baluta38395642013-11-09 01:00:00 +02001013 /* check if pending PS queue */
Joe Perchese1c77572013-03-18 10:44:39 -07001014 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
Teodora Balutaa7772892013-11-11 19:27:06 +02001015 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending\n",
Joe Perchese1c77572013-03-18 10:44:39 -07001016 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1017 if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1018 BSSvRemoveOneNode(pDevice, ii);
Teodora Balutaa7772892013-11-11 19:27:06 +02001019 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove\n", ii);
Joe Perchese1c77572013-03-18 10:44:39 -07001020 continue;
1021 }
1022 }
Forest Bond5449c682009-04-25 10:30:44 -04001023 }
1024
Joe Perchese1c77572013-03-18 10:44:39 -07001025 }
Forest Bond5449c682009-04-25 10:30:44 -04001026
Joe Perchese1c77572013-03-18 10:44:39 -07001027 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
Teodora Baluta38395642013-11-09 01:00:00 +02001028 /* on/off protect mode */
Joe Perchese1c77572013-03-18 10:44:39 -07001029 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1030 if (!pDevice->bProtectMode) {
1031 MACvEnableProtectMD(pDevice->PortOffset);
1032 pDevice->bProtectMode = true;
1033 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001034 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001035 if (pDevice->bProtectMode) {
1036 MACvDisableProtectMD(pDevice->PortOffset);
1037 pDevice->bProtectMode = false;
1038 }
1039 }
Teodora Baluta38395642013-11-09 01:00:00 +02001040 /* on/off short slot time */
Forest Bond5449c682009-04-25 10:30:44 -04001041
Joe Perchese1c77572013-03-18 10:44:39 -07001042 if (uNonShortSlotSTACnt > 0) {
1043 if (pDevice->bShortSlotTime) {
1044 pDevice->bShortSlotTime = false;
1045 BBvSetShortSlotTime(pDevice);
1046 vUpdateIFS((void *)pDevice);
1047 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001048 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001049 if (!pDevice->bShortSlotTime) {
1050 pDevice->bShortSlotTime = true;
1051 BBvSetShortSlotTime(pDevice);
1052 vUpdateIFS((void *)pDevice);
1053 }
1054 }
Forest Bond5449c682009-04-25 10:30:44 -04001055
Teodora Baluta38395642013-11-09 01:00:00 +02001056 /* on/off barker long preamble mode */
Forest Bond5449c682009-04-25 10:30:44 -04001057
Joe Perchese1c77572013-03-18 10:44:39 -07001058 if (uLongPreambleSTACnt > 0) {
1059 if (!pDevice->bBarkerPreambleMd) {
1060 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1061 pDevice->bBarkerPreambleMd = true;
1062 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001063 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001064 if (pDevice->bBarkerPreambleMd) {
1065 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1066 pDevice->bBarkerPreambleMd = false;
1067 }
1068 }
Forest Bond5449c682009-04-25 10:30:44 -04001069
Joe Perchese1c77572013-03-18 10:44:39 -07001070 }
Forest Bond5449c682009-04-25 10:30:44 -04001071
Teodora Baluta38395642013-11-09 01:00:00 +02001072 /* check if any STA in PS mode, enable DTIM multicast deliver */
Joe Perchese1c77572013-03-18 10:44:39 -07001073 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1074 if (uSleepySTACnt > 0)
1075 pMgmt->sNodeDBTable[0].bPSEnable = true;
1076 else
1077 pMgmt->sNodeDBTable[0].bPSEnable = false;
1078 }
Forest Bond5449c682009-04-25 10:30:44 -04001079
Joe Perchese1c77572013-03-18 10:44:39 -07001080 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1081 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
Jim Lieb612822f2009-08-12 14:54:03 -07001082
Joe Perchese1c77572013-03-18 10:44:39 -07001083 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1084 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
Teodora Baluta38395642013-11-09 01:00:00 +02001085 /* assoc with BSS */
1086 if (pMgmt->sNodeDBTable[0].bActive) {
Teodora Baluta347a0472013-11-09 01:00:01 +02001087 if (pDevice->bUpdateBBVGA)
Joe Perchese1c77572013-03-18 10:44:39 -07001088 s_vCheckPreEDThreshold((void *)pDevice);
Jim Lieb612822f2009-08-12 14:54:03 -07001089
Joe Perchese1c77572013-03-18 10:44:39 -07001090 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1091 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
1092 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1093 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1094 }
Forest Bond5449c682009-04-25 10:30:44 -04001095
Joe Perchese1c77572013-03-18 10:44:39 -07001096 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1097 pMgmt->sNodeDBTable[0].bActive = false;
1098 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1099 pMgmt->eCurrState = WMAC_STATE_IDLE;
1100 netif_stop_queue(pDevice->dev);
1101 pDevice->bLinkPass = false;
1102 pDevice->bRoaming = true;
1103 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1104 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1105 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1106 wpahdr->type = VIAWGET_DISASSOC_MSG;
1107 wpahdr->resp_ie_len = 0;
1108 wpahdr->req_ie_len = 0;
1109 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1110 pDevice->skb->dev = pDevice->wpadev;
1111 skb_reset_mac_header(pDevice->skb);
1112 pDevice->skb->pkt_type = PACKET_HOST;
1113 pDevice->skb->protocol = htons(ETH_P_802_2);
1114 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1115 netif_rx(pDevice->skb);
1116 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1117 }
1118#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
Joe Perchese1c77572013-03-18 10:44:39 -07001119 {
1120 union iwreq_data wrqu;
Guillaume Clement6b711272014-07-25 01:06:16 +02001121
Joe Perchese1c77572013-03-18 10:44:39 -07001122 memset(&wrqu, 0, sizeof(wrqu));
1123 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1124 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1125 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1126 }
1127#endif
1128 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001129 } else if (pItemSSID->len != 0) {
Joe Perchese1c77572013-03-18 10:44:39 -07001130 if (pDevice->uAutoReConnectTime < 10) {
1131 pDevice->uAutoReConnectTime++;
1132#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
Teodora Baluta38395642013-11-09 01:00:00 +02001133 /*
1134 * network manager support need not do
1135 * Roaming scan???
1136 */
Teodora Baluta2b0c2a42013-11-11 19:27:07 +02001137 if (pDevice->bWPASuppWextEnabled)
Joe Perchese1c77572013-03-18 10:44:39 -07001138 pDevice->uAutoReConnectTime = 0;
1139#endif
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001140 } else {
Teodora Baluta38395642013-11-09 01:00:00 +02001141 /*
1142 * mike use old encryption status
1143 * for wpa reauthentication
1144 */
Joe Perchese1c77572013-03-18 10:44:39 -07001145 if (pDevice->bWPADEVUp)
1146 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
Jim Lieb612822f2009-08-12 14:54:03 -07001147
Joe Perchese1c77572013-03-18 10:44:39 -07001148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1149 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1150 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1151 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1152 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1153 pDevice->uAutoReConnectTime = 0;
1154 }
1155 }
1156 }
Forest Bond5449c682009-04-25 10:30:44 -04001157
Joe Perchese1c77572013-03-18 10:44:39 -07001158 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Teodora Baluta38395642013-11-09 01:00:00 +02001159 /* if adhoc started which essid is NULL string, rescanning */
Joe Perchese1c77572013-03-18 10:44:39 -07001160 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1161 if (pDevice->uAutoReConnectTime < 10) {
1162 pDevice->uAutoReConnectTime++;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001163 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001164 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1165 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1166 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1167 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1168 pDevice->uAutoReConnectTime = 0;
Teodora Baluta88cc8502013-11-10 17:12:45 +02001169 }
Joe Perchese1c77572013-03-18 10:44:39 -07001170 }
1171 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
Teodora Baluta347a0472013-11-09 01:00:01 +02001172 if (pDevice->bUpdateBBVGA)
Joe Perchese1c77572013-03-18 10:44:39 -07001173 s_vCheckPreEDThreshold((void *)pDevice);
Joe Perchese1c77572013-03-18 10:44:39 -07001174 if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
1175 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1176 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1177 pMgmt->eCurrState = WMAC_STATE_STARTED;
1178 netif_stop_queue(pDevice->dev);
1179 pDevice->bLinkPass = false;
1180 }
1181 }
1182 }
Forest Bond5449c682009-04-25 10:30:44 -04001183
Joe Perchese1c77572013-03-18 10:44:39 -07001184 spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -04001185
Joe Perchese1c77572013-03-18 10:44:39 -07001186 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1187 add_timer(&pMgmt->sTimerSecondCallback);
Forest Bond5449c682009-04-25 10:30:44 -04001188}
1189
Forest Bond5449c682009-04-25 10:30:44 -04001190/*+
1191 *
1192 * Routine Description:
1193 *
1194 *
1195 * Update Tx attemps, Tx failure counter in Node DB
1196 *
1197 *
1198 * Return Value:
1199 * none.
1200 *
Joe Perchese1c77572013-03-18 10:44:39 -07001201 -*/
Forest Bond5449c682009-04-25 10:30:44 -04001202
Charles Clément6b35b7b2010-05-07 12:30:19 -07001203void
Forest Bond5449c682009-04-25 10:30:44 -04001204BSSvUpdateNodeTxCounter(
Joe Perchese1c77572013-03-18 10:44:39 -07001205 void *hDeviceContext,
1206 unsigned char byTsr0,
1207 unsigned char byTsr1,
1208 unsigned char *pbyBuffer,
1209 unsigned int uFIFOHeaderSize
1210)
Forest Bond5449c682009-04-25 10:30:44 -04001211{
Joe Perchese1c77572013-03-18 10:44:39 -07001212 PSDevice pDevice = (PSDevice)hDeviceContext;
1213 PSMgmtObject pMgmt = pDevice->pMgmt;
1214 unsigned int uNodeIndex = 0;
1215 unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1216 PSTxBufHead pTxBufHead;
1217 PS802_11Header pMACHeader;
1218 unsigned short wRate;
1219 unsigned short wFallBackRate = RATE_1M;
1220 unsigned char byFallBack;
1221 unsigned int ii;
Guillaume Clement6b711272014-07-25 01:06:16 +02001222
Joe Perchese1c77572013-03-18 10:44:39 -07001223 pTxBufHead = (PSTxBufHead) pbyBuffer;
Teodora Baluta347a0472013-11-09 01:00:01 +02001224 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0)
Joe Perchese1c77572013-03-18 10:44:39 -07001225 byFallBack = AUTO_FB_0;
Teodora Baluta347a0472013-11-09 01:00:01 +02001226 else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1)
Joe Perchese1c77572013-03-18 10:44:39 -07001227 byFallBack = AUTO_FB_1;
Teodora Baluta347a0472013-11-09 01:00:01 +02001228 else
Joe Perchese1c77572013-03-18 10:44:39 -07001229 byFallBack = AUTO_FB_NONE;
Teodora Baluta38395642013-11-09 01:00:00 +02001230 wRate = pTxBufHead->wReserved;
Forest Bond5449c682009-04-25 10:30:44 -04001231
Teodora Baluta38395642013-11-09 01:00:00 +02001232 /* Only Unicast using support rates */
Joe Perchese1c77572013-03-18 10:44:39 -07001233 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1235 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1236 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1237 if ((byTsr1 & TSR1_TERR) == 0) {
Teodora Baluta38395642013-11-09 01:00:00 +02001238 /* transmit success, TxAttempts at least plus one */
Joe Perchese1c77572013-03-18 10:44:39 -07001239 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1240 if ((byFallBack == AUTO_FB_NONE) ||
1241 (wRate < RATE_18M)) {
1242 wFallBackRate = wRate;
1243 } else if (byFallBack == AUTO_FB_0) {
Joe Perchese1c77572013-03-18 10:44:39 -07001244 if (byTxRetry < 5)
Joe Perchese1c77572013-03-18 10:44:39 -07001245 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
Joe Perchese1c77572013-03-18 10:44:39 -07001246 else
1247 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
Joe Perchese1c77572013-03-18 10:44:39 -07001248 } else if (byFallBack == AUTO_FB_1) {
1249 if (byTxRetry < 5)
1250 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1251 else
1252 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
Forest Bond5449c682009-04-25 10:30:44 -04001253 }
Joe Perchese1c77572013-03-18 10:44:39 -07001254 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1255 } else {
1256 pMgmt->sNodeDBTable[0].uTxFailures++;
1257 }
1258 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1259 if (byTxRetry != 0) {
1260 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
1261 if ((byFallBack == AUTO_FB_NONE) ||
1262 (wRate < RATE_18M)) {
1263 pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
1264 } else if (byFallBack == AUTO_FB_0) {
Teodora Baluta938db282013-11-09 01:00:03 +02001265 for (ii = 0; ii < byTxRetry; ii++) {
Teodora Baluta347a0472013-11-09 01:00:01 +02001266 if (ii < 5)
Joe Perchese1c77572013-03-18 10:44:39 -07001267 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
Teodora Baluta347a0472013-11-09 01:00:01 +02001268 else
Joe Perchese1c77572013-03-18 10:44:39 -07001269 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
Forest Bond5449c682009-04-25 10:30:44 -04001270 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
Joe Perchese1c77572013-03-18 10:44:39 -07001271 }
1272 } else if (byFallBack == AUTO_FB_1) {
1273 for (ii = 0; ii < byTxRetry; ii++) {
1274 if (ii < 5)
1275 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1276 else
1277 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1278 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1279 }
1280 }
1281 }
1282 }
Forest Bond5449c682009-04-25 10:30:44 -04001283
Joe Perchese1c77572013-03-18 10:44:39 -07001284 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1285 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
Joe Perchese1c77572013-03-18 10:44:39 -07001286 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
Forest Bond5449c682009-04-25 10:30:44 -04001287
Joe Perchese1c77572013-03-18 10:44:39 -07001288 if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
1289 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1290 if ((byTsr1 & TSR1_TERR) == 0) {
Teodora Baluta38395642013-11-09 01:00:00 +02001291 /* transmit success, TxAttempts at least plus one */
Joe Perchese1c77572013-03-18 10:44:39 -07001292 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1293 if ((byFallBack == AUTO_FB_NONE) ||
1294 (wRate < RATE_18M)) {
1295 wFallBackRate = wRate;
1296 } else if (byFallBack == AUTO_FB_0) {
1297 if (byTxRetry < 5)
1298 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1299 else
1300 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1301 } else if (byFallBack == AUTO_FB_1) {
1302 if (byTxRetry < 5)
1303 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1304 else
1305 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1306 }
1307 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1308 } else {
1309 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
1310 }
1311 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1312 if (byTxRetry != 0) {
1313 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
1314 if ((byFallBack == AUTO_FB_NONE) ||
1315 (wRate < RATE_18M)) {
1316 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
1317 } else if (byFallBack == AUTO_FB_0) {
1318 for (ii = 0; ii < byTxRetry; ii++) {
1319 if (ii < 5)
1320 wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
1321 else
1322 wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
1323 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1324 }
1325 } else if (byFallBack == AUTO_FB_1) {
1326 for (ii = 0; ii < byTxRetry; ii++) {
1327 if (ii < 5)
1328 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1329 else
1330 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1331 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1332 }
1333 }
1334 }
1335 }
1336 }
1337 }
Forest Bond5449c682009-04-25 10:30:44 -04001338}
1339
Forest Bond5449c682009-04-25 10:30:44 -04001340/*+
1341 *
1342 * Routine Description:
1343 * Clear Nodes & skb in DB Table
1344 *
1345 *
1346 * Parameters:
1347 * In:
1348 * hDeviceContext - The adapter context.
1349 * uStartIndex - starting index
1350 * Out:
1351 * none
1352 *
1353 * Return Value:
1354 * None.
1355 *
Joe Perchese1c77572013-03-18 10:44:39 -07001356 -*/
Forest Bond5449c682009-04-25 10:30:44 -04001357
Charles Clément6b35b7b2010-05-07 12:30:19 -07001358void
Forest Bond5449c682009-04-25 10:30:44 -04001359BSSvClearNodeDBTable(
Joe Perchese1c77572013-03-18 10:44:39 -07001360 void *hDeviceContext,
1361 unsigned int uStartIndex
1362)
Forest Bond5449c682009-04-25 10:30:44 -04001363
1364{
Joe Perchese1c77572013-03-18 10:44:39 -07001365 PSDevice pDevice = (PSDevice)hDeviceContext;
1366 PSMgmtObject pMgmt = pDevice->pMgmt;
1367 struct sk_buff *skb;
1368 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001369
Joe Perchese1c77572013-03-18 10:44:39 -07001370 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1371 if (pMgmt->sNodeDBTable[ii].bActive) {
Teodora Baluta38395642013-11-09 01:00:00 +02001372 /* check if sTxPSQueue has been initial */
Joe Perchese1c77572013-03-18 10:44:39 -07001373 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1374 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
1375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1376 dev_kfree_skb(skb);
1377 }
1378 }
1379 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1380 }
1381 }
Forest Bond5449c682009-04-25 10:30:44 -04001382
Joe Perchese1c77572013-03-18 10:44:39 -07001383 return;
Forest Bond5449c682009-04-25 10:30:44 -04001384};
1385
Charles Clément6b35b7b2010-05-07 12:30:19 -07001386void s_vCheckSensitivity(
Joe Perchese1c77572013-03-18 10:44:39 -07001387 void *hDeviceContext
1388)
Forest Bond5449c682009-04-25 10:30:44 -04001389{
Joe Perchese1c77572013-03-18 10:44:39 -07001390 PSDevice pDevice = (PSDevice)hDeviceContext;
1391 PKnownBSS pBSSList = NULL;
1392 PSMgmtObject pMgmt = pDevice->pMgmt;
1393 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001394
Joe Perchese1c77572013-03-18 10:44:39 -07001395 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1396 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1397 return;
1398 }
Forest Bond5449c682009-04-25 10:30:44 -04001399
Joe Perchese1c77572013-03-18 10:44:39 -07001400 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1401 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1402 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1403 if (pBSSList != NULL) {
Teodora Baluta38395642013-11-09 01:00:00 +02001404 /* Update BB Reg if RSSI is too strong */
Joe Perchese1c77572013-03-18 10:44:39 -07001405 long LocalldBmAverage = 0;
1406 long uNumofdBm = 0;
Guillaume Clement6b711272014-07-25 01:06:16 +02001407
Joe Perchese1c77572013-03-18 10:44:39 -07001408 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1409 if (pBSSList->ldBmAverage[ii] != 0) {
1410 uNumofdBm++;
1411 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1412 }
1413 }
1414 if (uNumofdBm > 0) {
1415 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1416 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1418 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1419 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1420 break;
1421 }
1422 }
1423 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1424 pDevice->uBBVGADiffCount++;
1425 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1426 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1427 } else {
1428 pDevice->uBBVGADiffCount = 0;
1429 }
1430 }
1431 }
1432 }
Forest Bond5449c682009-04-25 10:30:44 -04001433}
1434
Charles Clément6b35b7b2010-05-07 12:30:19 -07001435void
Joe Perchese1c77572013-03-18 10:44:39 -07001436BSSvClearAnyBSSJoinRecord(
1437 void *hDeviceContext
1438)
Forest Bond5449c682009-04-25 10:30:44 -04001439{
Joe Perchese1c77572013-03-18 10:44:39 -07001440 PSDevice pDevice = (PSDevice)hDeviceContext;
1441 PSMgmtObject pMgmt = pDevice->pMgmt;
1442 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001443
Teodora Baluta347a0472013-11-09 01:00:01 +02001444 for (ii = 0; ii < MAX_BSS_NUM; ii++)
Joe Perchese1c77572013-03-18 10:44:39 -07001445 pMgmt->sBSSList[ii].bSelected = false;
Forest Bond5449c682009-04-25 10:30:44 -04001446}
1447
1448#ifdef Calcu_LinkQual
Charles Clément6b35b7b2010-05-07 12:30:19 -07001449void s_uCalculateLinkQual(
Joe Perchese1c77572013-03-18 10:44:39 -07001450 void *hDeviceContext
1451)
Forest Bond5449c682009-04-25 10:30:44 -04001452{
Joe Perchese1c77572013-03-18 10:44:39 -07001453 PSDevice pDevice = (PSDevice)hDeviceContext;
1454 unsigned long TxOkRatio, TxCnt;
1455 unsigned long RxOkRatio, RxCnt;
1456 unsigned long RssiRatio;
1457 long ldBm;
Forest Bond5449c682009-04-25 10:30:44 -04001458
Joe Perchese1c77572013-03-18 10:44:39 -07001459 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1460 pDevice->scStatistic.TxRetryOkCount +
1461 pDevice->scStatistic.TxFailCount;
1462 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1463 pDevice->scStatistic.RxOkCnt;
1464 TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1465 RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
Teodora Baluta38395642013-11-09 01:00:00 +02001466 /* decide link quality */
Teodora Baluta2b0c2a42013-11-11 19:27:07 +02001467 if (!pDevice->bLinkPass) {
Joe Perchese1c77572013-03-18 10:44:39 -07001468 pDevice->scStatistic.LinkQuality = 0;
1469 pDevice->scStatistic.SignalStren = 0;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001470 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001471 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
Teodora Baluta347a0472013-11-09 01:00:01 +02001472 if (-ldBm < 50)
Joe Perchese1c77572013-03-18 10:44:39 -07001473 RssiRatio = 4000;
Teodora Baluta347a0472013-11-09 01:00:01 +02001474 else if (-ldBm > 90)
Joe Perchese1c77572013-03-18 10:44:39 -07001475 RssiRatio = 0;
Teodora Baluta347a0472013-11-09 01:00:01 +02001476 else
Joe Perchese1c77572013-03-18 10:44:39 -07001477 RssiRatio = (40-(-ldBm-50))*4000/40;
Joe Perchese1c77572013-03-18 10:44:39 -07001478 pDevice->scStatistic.SignalStren = RssiRatio/40;
1479 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1480 }
1481 pDevice->scStatistic.RxFcsErrCnt = 0;
1482 pDevice->scStatistic.RxOkCnt = 0;
1483 pDevice->scStatistic.TxFailCount = 0;
1484 pDevice->scStatistic.TxNoRetryOkCount = 0;
1485 pDevice->scStatistic.TxRetryOkCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001486}
1487#endif
1488
Charles Clément6b35b7b2010-05-07 12:30:19 -07001489void s_vCheckPreEDThreshold(
Joe Perchese1c77572013-03-18 10:44:39 -07001490 void *hDeviceContext
1491)
Forest Bond5449c682009-04-25 10:30:44 -04001492{
Joe Perchese1c77572013-03-18 10:44:39 -07001493 PSDevice pDevice = (PSDevice)hDeviceContext;
1494 PKnownBSS pBSSList = NULL;
1495 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
Forest Bond5449c682009-04-25 10:30:44 -04001496
Joe Perchese1c77572013-03-18 10:44:39 -07001497 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1498 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1499 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
Teodora Baluta347a0472013-11-09 01:00:01 +02001500 if (pBSSList != NULL)
Joe Perchese1c77572013-03-18 10:44:39 -07001501 pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
Joe Perchese1c77572013-03-18 10:44:39 -07001502 }
Forest Bond5449c682009-04-25 10:30:44 -04001503}