blob: eb3474da93498697d31303f92dc7efffd16a8275 [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
Joe Perchese1c77572013-03-18 10:44:39 -0700266 return;
Forest Bond5449c682009-04-25 10:30:44 -0400267}
268
Forest Bond5449c682009-04-25 10:30:44 -0400269/*+
270 *
271 * Routine Description:
272 * search BSS list by BSSID & SSID if matched
273 *
274 * Return Value:
Charles Clément1b120682010-08-01 17:15:48 +0200275 * true if found.
Forest Bond5449c682009-04-25 10:30:44 -0400276 *
Joe Perchese1c77572013-03-18 10:44:39 -0700277 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400278PKnownBSS
279BSSpAddrIsInBSSList(
Joe Perchese1c77572013-03-18 10:44:39 -0700280 void *hDeviceContext,
281 unsigned char *abyBSSID,
282 PWLAN_IE_SSID pSSID
283)
Forest Bond5449c682009-04-25 10:30:44 -0400284{
Joe Perchese1c77572013-03-18 10:44:39 -0700285 PSDevice pDevice = (PSDevice)hDeviceContext;
286 PSMgmtObject pMgmt = pDevice->pMgmt;
287 PKnownBSS pBSSList = NULL;
288 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400289
Joe Perchese1c77572013-03-18 10:44:39 -0700290 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
291 pBSSList = &(pMgmt->sBSSList[ii]);
292 if (pBSSList->bActive) {
Joe Perches83294192013-09-01 12:15:47 -0700293 if (ether_addr_equal(pBSSList->abyBSSID, abyBSSID)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700294 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len) {
295 if (memcmp(pSSID->abySSID,
296 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
297 pSSID->len) == 0)
298 return pBSSList;
299 }
300 }
301 }
302 }
Forest Bond5449c682009-04-25 10:30:44 -0400303
Joe Perchese1c77572013-03-18 10:44:39 -0700304 return NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400305};
306
Forest Bond5449c682009-04-25 10:30:44 -0400307/*+
308 *
309 * Routine Description:
310 * Insert a BSS set into known BSS list
311 *
312 * Return Value:
Charles Clément1b120682010-08-01 17:15:48 +0200313 * true if success.
Forest Bond5449c682009-04-25 10:30:44 -0400314 *
Joe Perchese1c77572013-03-18 10:44:39 -0700315 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400316
Charles Clément7b6a0012010-08-01 17:15:50 +0200317bool
Joe Perchese1c77572013-03-18 10:44:39 -0700318BSSbInsertToBSSList(
319 void *hDeviceContext,
320 unsigned char *abyBSSIDAddr,
321 QWORD qwTimestamp,
322 unsigned short wBeaconInterval,
323 unsigned short wCapInfo,
324 unsigned char byCurrChannel,
325 PWLAN_IE_SSID pSSID,
326 PWLAN_IE_SUPP_RATES pSuppRates,
327 PWLAN_IE_SUPP_RATES pExtSuppRates,
328 PERPObject psERP,
329 PWLAN_IE_RSN pRSN,
330 PWLAN_IE_RSN_EXT pRSNWPA,
331 PWLAN_IE_COUNTRY pIE_Country,
332 PWLAN_IE_QUIET pIE_Quiet,
333 unsigned int uIELength,
334 unsigned char *pbyIEs,
335 void *pRxPacketContext
336)
Forest Bond5449c682009-04-25 10:30:44 -0400337{
Joe Perchese1c77572013-03-18 10:44:39 -0700338 PSDevice pDevice = (PSDevice)hDeviceContext;
339 PSMgmtObject pMgmt = pDevice->pMgmt;
340 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
341 PKnownBSS pBSSList = NULL;
342 unsigned int ii;
343 bool bParsingQuiet = false;
344 PWLAN_IE_QUIET pQuiet = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400345
Joe Perchese1c77572013-03-18 10:44:39 -0700346 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
Forest Bond5449c682009-04-25 10:30:44 -0400347
Joe Perchese1c77572013-03-18 10:44:39 -0700348 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
349 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
350 if (!pBSSList->bActive)
351 break;
352 }
Forest Bond5449c682009-04-25 10:30:44 -0400353
Joe Perchese1c77572013-03-18 10:44:39 -0700354 if (ii == MAX_BSS_NUM) {
355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
356 return false;
357 }
Teodora Baluta38395642013-11-09 01:00:00 +0200358 /* save the BSS info */
Joe Perchese1c77572013-03-18 10:44:39 -0700359 pBSSList->bActive = true;
360 memcpy(pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
361 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
362 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
363 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
364 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
365 pBSSList->uClearCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400366
Joe Perchese1c77572013-03-18 10:44:39 -0700367 if (pSSID->len > WLAN_SSID_MAXLEN)
368 pSSID->len = WLAN_SSID_MAXLEN;
369 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -0400370
Joe Perchese1c77572013-03-18 10:44:39 -0700371 pBSSList->uChannel = byCurrChannel;
Forest Bond5449c682009-04-25 10:30:44 -0400372
Joe Perchese1c77572013-03-18 10:44:39 -0700373 if (pSuppRates->len > WLAN_RATES_MAXLEN)
374 pSuppRates->len = WLAN_RATES_MAXLEN;
375 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -0400376
Joe Perchese1c77572013-03-18 10:44:39 -0700377 if (pExtSuppRates != NULL) {
378 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
379 pExtSuppRates->len = WLAN_RATES_MAXLEN;
380 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
Forest Bond5449c682009-04-25 10:30:44 -0400382
Joe Perchese1c77572013-03-18 10:44:39 -0700383 } else {
384 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
385 }
386 pBSSList->sERP.byERP = psERP->byERP;
387 pBSSList->sERP.bERPExist = psERP->bERPExist;
Forest Bond5449c682009-04-25 10:30:44 -0400388
Teodora Baluta38395642013-11-09 01:00:00 +0200389 /* check if BSS is 802.11a/b/g */
Joe Perchese1c77572013-03-18 10:44:39 -0700390 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
391 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
392 } else {
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200393 if (pBSSList->sERP.bERPExist)
Joe Perchese1c77572013-03-18 10:44:39 -0700394 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
Teodora Baluta347a0472013-11-09 01:00:01 +0200395 else
Joe Perchese1c77572013-03-18 10:44:39 -0700396 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
Joe Perchese1c77572013-03-18 10:44:39 -0700397 }
Forest Bond5449c682009-04-25 10:30:44 -0400398
Joe Perchese1c77572013-03-18 10:44:39 -0700399 pBSSList->byRxRate = pRxPacket->byRxRate;
400 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
401 pBSSList->uRSSI = pRxPacket->uRSSI;
402 pBSSList->bySQ = pRxPacket->bySQ;
Forest Bond5449c682009-04-25 10:30:44 -0400403
Joe Perchese1c77572013-03-18 10:44:39 -0700404 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
405 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200406 /* assoc with BSS */
Teodora Baluta347a0472013-11-09 01:00:01 +0200407 if (pBSSList == pMgmt->pCurrBSS)
Joe Perchese1c77572013-03-18 10:44:39 -0700408 bParsingQuiet = true;
Joe Perchese1c77572013-03-18 10:44:39 -0700409 }
Forest Bond5449c682009-04-25 10:30:44 -0400410
Joe Perchese1c77572013-03-18 10:44:39 -0700411 WPA_ClearRSN(pBSSList);
Forest Bond5449c682009-04-25 10:30:44 -0400412
Joe Perchese1c77572013-03-18 10:44:39 -0700413 if (pRSNWPA != NULL) {
414 unsigned int uLen = pRSNWPA->len + 2;
Forest Bond5449c682009-04-25 10:30:44 -0400415
Joe Perchese1c77572013-03-18 10:44:39 -0700416 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
417 pBSSList->wWPALen = uLen;
418 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
419 WPA_ParseRSN(pBSSList, pRSNWPA);
420 }
421 }
Forest Bond5449c682009-04-25 10:30:44 -0400422
Joe Perchese1c77572013-03-18 10:44:39 -0700423 WPA2_ClearRSN(pBSSList);
Forest Bond5449c682009-04-25 10:30:44 -0400424
Joe Perchese1c77572013-03-18 10:44:39 -0700425 if (pRSN != NULL) {
426 unsigned int uLen = pRSN->len + 2;
427 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
428 pBSSList->wRSNLen = uLen;
429 memcpy(pBSSList->byRSNIE, pRSN, uLen);
430 WPA2vParseRSN(pBSSList, pRSN);
431 }
432 }
Forest Bond5449c682009-04-25 10:30:44 -0400433
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200434 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || pBSSList->bWPA2Valid) {
Joe Perchese1c77572013-03-18 10:44:39 -0700435 PSKeyItem pTransmitKey = NULL;
436 bool bIs802_1x = false;
Forest Bond5449c682009-04-25 10:30:44 -0400437
Joe Perchese1c77572013-03-18 10:44:39 -0700438 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii++) {
439 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
440 bIs802_1x = true;
441 break;
442 }
443 }
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200444 if (bIs802_1x && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
Joe Perchese1c77572013-03-18 10:44:39 -0700445 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
Joe Perchese1c77572013-03-18 10:44:39 -0700446 bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
Forest Bond5449c682009-04-25 10:30:44 -0400447
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200448 if (pDevice->bLinkPass && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
449 if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) ||
450 KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700451 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
452 pDevice->gsPMKIDCandidate.Version = 1;
Forest Bond5449c682009-04-25 10:30:44 -0400453
Joe Perchese1c77572013-03-18 10:44:39 -0700454 }
Forest Bond5449c682009-04-25 10:30:44 -0400455
Joe Perchese1c77572013-03-18 10:44:39 -0700456 }
457 }
458 }
Forest Bond5449c682009-04-25 10:30:44 -0400459
Joe Perchese1c77572013-03-18 10:44:39 -0700460 if (pDevice->bUpdateBBVGA) {
Teodora Baluta38395642013-11-09 01:00:00 +0200461 /* monitor if RSSI is too strong */
Joe Perchese1c77572013-03-18 10:44:39 -0700462 pBSSList->byRSSIStatCnt = 0;
463 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
464 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
465 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
466 pBSSList->ldBmAverage[ii] = 0;
467 }
Forest Bond5449c682009-04-25 10:30:44 -0400468
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200469 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
Joe Perchese1c77572013-03-18 10:44:39 -0700470 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
471 pIE_Country);
472 }
Forest Bond5449c682009-04-25 10:30:44 -0400473
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200474 if (bParsingQuiet && (pIE_Quiet != NULL)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700475 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
476 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200477 /* valid EID */
Joe Perchese1c77572013-03-18 10:44:39 -0700478 if (pQuiet == NULL) {
479 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
480 CARDbSetQuiet(pMgmt->pAdapter,
481 true,
482 pQuiet->byQuietCount,
483 pQuiet->byQuietPeriod,
484 *((unsigned short *)pQuiet->abyQuietDuration),
485 *((unsigned short *)pQuiet->abyQuietOffset)
486);
487 } else {
488 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
489 CARDbSetQuiet(pMgmt->pAdapter,
490 false,
491 pQuiet->byQuietCount,
492 pQuiet->byQuietPeriod,
493 *((unsigned short *)pQuiet->abyQuietDuration),
494 *((unsigned short *)pQuiet->abyQuietOffset)
495 );
496 }
497 }
498 }
Forest Bond5449c682009-04-25 10:30:44 -0400499
Guido Martínezbc5cf652014-04-19 16:45:00 -0300500 if (bParsingQuiet && (pQuiet != NULL))
Joe Perchese1c77572013-03-18 10:44:39 -0700501 CARDbStartQuiet(pMgmt->pAdapter);
Forest Bond5449c682009-04-25 10:30:44 -0400502
Joe Perchese1c77572013-03-18 10:44:39 -0700503 pBSSList->uIELength = uIELength;
504 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
505 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
506 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
Forest Bond5449c682009-04-25 10:30:44 -0400507
Joe Perchese1c77572013-03-18 10:44:39 -0700508 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400509}
510
Forest Bond5449c682009-04-25 10:30:44 -0400511/*+
512 *
513 * Routine Description:
514 * Update BSS set in known BSS list
515 *
516 * Return Value:
Charles Clément1b120682010-08-01 17:15:48 +0200517 * true if success.
Forest Bond5449c682009-04-25 10:30:44 -0400518 *
Joe Perchese1c77572013-03-18 10:44:39 -0700519 -*/
Teodora Baluta38395642013-11-09 01:00:00 +0200520/* TODO: input structure modify */
Forest Bond5449c682009-04-25 10:30:44 -0400521
Charles Clément7b6a0012010-08-01 17:15:50 +0200522bool
Joe Perchese1c77572013-03-18 10:44:39 -0700523BSSbUpdateToBSSList(
524 void *hDeviceContext,
525 QWORD qwTimestamp,
526 unsigned short wBeaconInterval,
527 unsigned short wCapInfo,
528 unsigned char byCurrChannel,
529 bool bChannelHit,
530 PWLAN_IE_SSID pSSID,
531 PWLAN_IE_SUPP_RATES pSuppRates,
532 PWLAN_IE_SUPP_RATES pExtSuppRates,
533 PERPObject psERP,
534 PWLAN_IE_RSN pRSN,
535 PWLAN_IE_RSN_EXT pRSNWPA,
536 PWLAN_IE_COUNTRY pIE_Country,
537 PWLAN_IE_QUIET pIE_Quiet,
538 PKnownBSS pBSSList,
539 unsigned int uIELength,
540 unsigned char *pbyIEs,
541 void *pRxPacketContext
542)
Forest Bond5449c682009-04-25 10:30:44 -0400543{
Joe Perchese1c77572013-03-18 10:44:39 -0700544 int ii;
545 PSDevice pDevice = (PSDevice)hDeviceContext;
546 PSMgmtObject pMgmt = pDevice->pMgmt;
547 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
548 long ldBm;
549 bool bParsingQuiet = false;
550 PWLAN_IE_QUIET pQuiet = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400551
Joe Perchese1c77572013-03-18 10:44:39 -0700552 if (pBSSList == NULL)
553 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400554
Joe Perchese1c77572013-03-18 10:44:39 -0700555 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
556 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
557 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
558 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
559 pBSSList->uClearCount = 0;
560 pBSSList->uChannel = byCurrChannel;
Forest Bond5449c682009-04-25 10:30:44 -0400561
Joe Perchese1c77572013-03-18 10:44:39 -0700562 if (pSSID->len > WLAN_SSID_MAXLEN)
563 pSSID->len = WLAN_SSID_MAXLEN;
Forest Bond5449c682009-04-25 10:30:44 -0400564
Joe Perchese1c77572013-03-18 10:44:39 -0700565 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
566 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
567 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -0400568
Teodora Baluta347a0472013-11-09 01:00:01 +0200569 if (pExtSuppRates != NULL)
Joe Perchese1c77572013-03-18 10:44:39 -0700570 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
Teodora Baluta347a0472013-11-09 01:00:01 +0200571 else
Joe Perchese1c77572013-03-18 10:44:39 -0700572 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
Joe Perchese1c77572013-03-18 10:44:39 -0700573 pBSSList->sERP.byERP = psERP->byERP;
574 pBSSList->sERP.bERPExist = psERP->bERPExist;
Forest Bond5449c682009-04-25 10:30:44 -0400575
Teodora Baluta38395642013-11-09 01:00:00 +0200576 /* check if BSS is 802.11a/b/g */
Joe Perchese1c77572013-03-18 10:44:39 -0700577 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
578 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
579 } else {
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200580 if (pBSSList->sERP.bERPExist)
Joe Perchese1c77572013-03-18 10:44:39 -0700581 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
Teodora Baluta347a0472013-11-09 01:00:01 +0200582 else
Joe Perchese1c77572013-03-18 10:44:39 -0700583 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
Joe Perchese1c77572013-03-18 10:44:39 -0700584 }
Forest Bond5449c682009-04-25 10:30:44 -0400585
Joe Perchese1c77572013-03-18 10:44:39 -0700586 pBSSList->byRxRate = pRxPacket->byRxRate;
587 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
588 if (bChannelHit)
589 pBSSList->uRSSI = pRxPacket->uRSSI;
590 pBSSList->bySQ = pRxPacket->bySQ;
Forest Bond5449c682009-04-25 10:30:44 -0400591
Joe Perchese1c77572013-03-18 10:44:39 -0700592 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
593 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200594 /* assoc with BSS */
Teodora Baluta347a0472013-11-09 01:00:01 +0200595 if (pBSSList == pMgmt->pCurrBSS)
Joe Perchese1c77572013-03-18 10:44:39 -0700596 bParsingQuiet = true;
Joe Perchese1c77572013-03-18 10:44:39 -0700597 }
Forest Bond5449c682009-04-25 10:30:44 -0400598
Teodora Baluta38395642013-11-09 01:00:00 +0200599 WPA_ClearRSN(pBSSList); /* mike update */
Forest Bond5449c682009-04-25 10:30:44 -0400600
Joe Perchese1c77572013-03-18 10:44:39 -0700601 if (pRSNWPA != NULL) {
602 unsigned int uLen = pRSNWPA->len + 2;
603 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;
614 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
615 pBSSList->wRSNLen = uLen;
616 memcpy(pBSSList->byRSNIE, pRSN, uLen);
617 WPA2vParseRSN(pBSSList, pRSN);
618 }
619 }
Forest Bond5449c682009-04-25 10:30:44 -0400620
Joe Perchese1c77572013-03-18 10:44:39 -0700621 if (pRxPacket->uRSSI != 0) {
622 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
Teodora Baluta38395642013-11-09 01:00:00 +0200623 /* monitor if RSSI is too strong */
Joe Perchese1c77572013-03-18 10:44:39 -0700624 pBSSList->byRSSIStatCnt++;
625 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
626 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
627 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
Teodora Baluta347a0472013-11-09 01:00:01 +0200628 if (pBSSList->ldBmAverage[ii] != 0)
Joe Perchese1c77572013-03-18 10:44:39 -0700629 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
Joe Perchese1c77572013-03-18 10:44:39 -0700630 }
631 }
Forest Bond5449c682009-04-25 10:30:44 -0400632
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200633 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
Joe Perchese1c77572013-03-18 10:44:39 -0700634 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
635 pIE_Country);
636 }
Forest Bond5449c682009-04-25 10:30:44 -0400637
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200638 if (bParsingQuiet && (pIE_Quiet != NULL)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700639 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
640 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
Teodora Baluta38395642013-11-09 01:00:00 +0200641 /* valid EID */
Joe Perchese1c77572013-03-18 10:44:39 -0700642 if (pQuiet == NULL) {
643 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
644 CARDbSetQuiet(pMgmt->pAdapter,
645 true,
646 pQuiet->byQuietCount,
647 pQuiet->byQuietPeriod,
648 *((unsigned short *)pQuiet->abyQuietDuration),
649 *((unsigned short *)pQuiet->abyQuietOffset)
650);
651 } else {
652 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
653 CARDbSetQuiet(pMgmt->pAdapter,
654 false,
655 pQuiet->byQuietCount,
656 pQuiet->byQuietPeriod,
657 *((unsigned short *)pQuiet->abyQuietDuration),
658 *((unsigned short *)pQuiet->abyQuietOffset)
659 );
660 }
661 }
662 }
Forest Bond5449c682009-04-25 10:30:44 -0400663
Guido Martínezbc5cf652014-04-19 16:45:00 -0300664 if (bParsingQuiet && (pQuiet != NULL))
Joe Perchese1c77572013-03-18 10:44:39 -0700665 CARDbStartQuiet(pMgmt->pAdapter);
Forest Bond5449c682009-04-25 10:30:44 -0400666
Joe Perchese1c77572013-03-18 10:44:39 -0700667 pBSSList->uIELength = uIELength;
668 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
669 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
670 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
Forest Bond5449c682009-04-25 10:30:44 -0400671
Joe Perchese1c77572013-03-18 10:44:39 -0700672 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400673}
674
Forest Bond5449c682009-04-25 10:30:44 -0400675/*+
676 *
677 * Routine Description:
678 * Search Node DB table to find the index of matched DstAddr
679 *
680 * Return Value:
681 * None
682 *
Joe Perchese1c77572013-03-18 10:44:39 -0700683 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400684
Charles Clément7b6a0012010-08-01 17:15:50 +0200685bool
Charles Clémentfe4f34b2010-06-25 10:48:53 -0700686BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
Joe Perchese1c77572013-03-18 10:44:39 -0700687 unsigned int *puNodeIndex)
Forest Bond5449c682009-04-25 10:30:44 -0400688{
Joe Perchese1c77572013-03-18 10:44:39 -0700689 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
690 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400691
Teodora Baluta38395642013-11-09 01:00:00 +0200692 /* Index = 0 reserved for AP Node */
Joe Perchese1c77572013-03-18 10:44:39 -0700693 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
694 if (pMgmt->sNodeDBTable[ii].bActive) {
Joe Perches83294192013-09-01 12:15:47 -0700695 if (ether_addr_equal(abyDstAddr,
696 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700697 *puNodeIndex = ii;
698 return true;
699 }
700 }
701 }
Forest Bond5449c682009-04-25 10:30:44 -0400702
Joe Perchese1c77572013-03-18 10:44:39 -0700703 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400704};
705
Forest Bond5449c682009-04-25 10:30:44 -0400706/*+
707 *
708 * Routine Description:
Justin P. Mattock789d1ae2012-08-20 08:43:13 -0700709 * Find an empty node and allocat it; if there is no empty node,
710 * then use the most inactive one.
Forest Bond5449c682009-04-25 10:30:44 -0400711 *
712 * Return Value:
713 * None
714 *
Joe Perchese1c77572013-03-18 10:44:39 -0700715 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700716void
Charles Clémentfe4f34b2010-06-25 10:48:53 -0700717BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
Forest Bond5449c682009-04-25 10:30:44 -0400718{
Joe Perchese1c77572013-03-18 10:44:39 -0700719 PSDevice pDevice = (PSDevice)hDeviceContext;
720 PSMgmtObject pMgmt = pDevice->pMgmt;
721 unsigned int ii;
722 unsigned int BigestCount = 0;
723 unsigned int SelectIndex;
724 struct sk_buff *skb;
Teodora Baluta38395642013-11-09 01:00:00 +0200725 /*
726 * Index = 0 reserved for AP Node (In STA mode)
727 * Index = 0 reserved for Broadcast/MultiCast (In AP mode)
728 */
Joe Perchese1c77572013-03-18 10:44:39 -0700729 SelectIndex = 1;
730 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
731 if (pMgmt->sNodeDBTable[ii].bActive) {
732 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
733 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
734 SelectIndex = ii;
735 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700736 } else {
Joe Perchese1c77572013-03-18 10:44:39 -0700737 break;
738 }
739 }
Forest Bond5449c682009-04-25 10:30:44 -0400740
Teodora Baluta38395642013-11-09 01:00:00 +0200741 /* if not found replace uInActiveCount is largest one */
Joe Perchese1c77572013-03-18 10:44:39 -0700742 if (ii == (MAX_NODE_NUM + 1)) {
743 *puNodeIndex = SelectIndex;
744 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
Teodora Baluta38395642013-11-09 01:00:00 +0200745 /* clear ps buffer */
Joe Perchese1c77572013-03-18 10:44:39 -0700746 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
747 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
748 dev_kfree_skb(skb);
749 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700750 } else {
Joe Perchese1c77572013-03-18 10:44:39 -0700751 *puNodeIndex = ii;
752 }
Forest Bond5449c682009-04-25 10:30:44 -0400753
Joe Perchese1c77572013-03-18 10:44:39 -0700754 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
755 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
756 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
Teodora Baluta38395642013-11-09 01:00:00 +0200757 /* for AP mode PS queue */
Joe Perchese1c77572013-03-18 10:44:39 -0700758 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
759 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
760 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
762 return;
Forest Bond5449c682009-04-25 10:30:44 -0400763};
764
Forest Bond5449c682009-04-25 10:30:44 -0400765/*+
766 *
767 * Routine Description:
768 * Remove Node by NodeIndex
769 *
770 *
771 * Return Value:
772 * None
773 *
Joe Perchese1c77572013-03-18 10:44:39 -0700774 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700775void
Forest Bond5449c682009-04-25 10:30:44 -0400776BSSvRemoveOneNode(
Joe Perchese1c77572013-03-18 10:44:39 -0700777 void *hDeviceContext,
778 unsigned int uNodeIndex
779)
Forest Bond5449c682009-04-25 10:30:44 -0400780{
Joe Perchese1c77572013-03-18 10:44:39 -0700781 PSDevice pDevice = (PSDevice)hDeviceContext;
782 PSMgmtObject pMgmt = pDevice->pMgmt;
783 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
784 struct sk_buff *skb;
Forest Bond5449c682009-04-25 10:30:44 -0400785
Joe Perchese1c77572013-03-18 10:44:39 -0700786 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
787 dev_kfree_skb(skb);
Teodora Baluta38395642013-11-09 01:00:00 +0200788 /* clear context */
Joe Perchese1c77572013-03-18 10:44:39 -0700789 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
Teodora Baluta38395642013-11-09 01:00:00 +0200790 /* clear tx bit map */
Joe Perchese1c77572013-03-18 10:44:39 -0700791 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
Forest Bond5449c682009-04-25 10:30:44 -0400792
Joe Perchese1c77572013-03-18 10:44:39 -0700793 return;
Forest Bond5449c682009-04-25 10:30:44 -0400794};
795/*+
796 *
797 * Routine Description:
798 * Update AP Node content in Index 0 of KnownNodeDB
799 *
800 *
801 * Return Value:
802 * None
803 *
Joe Perchese1c77572013-03-18 10:44:39 -0700804 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400805
Charles Clément6b35b7b2010-05-07 12:30:19 -0700806void
Forest Bond5449c682009-04-25 10:30:44 -0400807BSSvUpdateAPNode(
Joe Perchese1c77572013-03-18 10:44:39 -0700808 void *hDeviceContext,
809 unsigned short *pwCapInfo,
810 PWLAN_IE_SUPP_RATES pSuppRates,
811 PWLAN_IE_SUPP_RATES pExtSuppRates
812)
Forest Bond5449c682009-04-25 10:30:44 -0400813{
Joe Perchese1c77572013-03-18 10:44:39 -0700814 PSDevice pDevice = (PSDevice)hDeviceContext;
815 PSMgmtObject pMgmt = pDevice->pMgmt;
816 unsigned int uRateLen = WLAN_RATES_MAXLEN;
Forest Bond5449c682009-04-25 10:30:44 -0400817
Joe Perchese1c77572013-03-18 10:44:39 -0700818 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
Forest Bond5449c682009-04-25 10:30:44 -0400819
Joe Perchese1c77572013-03-18 10:44:39 -0700820 pMgmt->sNodeDBTable[0].bActive = true;
Teodora Baluta347a0472013-11-09 01:00:01 +0200821 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
Joe Perchese1c77572013-03-18 10:44:39 -0700822 uRateLen = WLAN_RATES_MAXLEN_11B;
Joe Perchese1c77572013-03-18 10:44:39 -0700823 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
824 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
825 uRateLen);
826 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
827 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
828 uRateLen);
829 RATEvParseMaxRate((void *)pDevice,
830 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
831 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
832 true,
833 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
834 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
835 &(pMgmt->sNodeDBTable[0].wSuppRate),
836 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
837 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
838);
839 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
840 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
841 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
842 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
Teodora Baluta18278772013-11-11 19:27:05 +0200843 netdev_dbg(pDevice->dev, "BSSvUpdateAPNode:MaxSuppRate is %d\n",
844 pMgmt->sNodeDBTable[0].wMaxSuppRate);
Teodora Baluta38395642013-11-09 01:00:00 +0200845 /* auto rate fallback function initiation */
Teodora Balutaa7772892013-11-11 19:27:06 +0200846 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->sNodeDBTable[0].wTxDataRate = %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
Forest Bond5449c682009-04-25 10:30:44 -0400847};
848
Forest Bond5449c682009-04-25 10:30:44 -0400849/*+
850 *
851 * Routine Description:
852 * Add Multicast Node content in Index 0 of KnownNodeDB
853 *
854 *
855 * Return Value:
856 * None
857 *
Joe Perchese1c77572013-03-18 10:44:39 -0700858 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400859
Charles Clément6b35b7b2010-05-07 12:30:19 -0700860void
Forest Bond5449c682009-04-25 10:30:44 -0400861BSSvAddMulticastNode(
Joe Perchese1c77572013-03-18 10:44:39 -0700862 void *hDeviceContext
863)
Forest Bond5449c682009-04-25 10:30:44 -0400864{
Joe Perchese1c77572013-03-18 10:44:39 -0700865 PSDevice pDevice = (PSDevice)hDeviceContext;
866 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -0400867
Joe Perchese1c77572013-03-18 10:44:39 -0700868 if (!pDevice->bEnableHostWEP)
869 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
870 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
871 pMgmt->sNodeDBTable[0].bActive = true;
872 pMgmt->sNodeDBTable[0].bPSEnable = false;
873 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
874 RATEvParseMaxRate((void *)pDevice,
875 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
876 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
877 true,
878 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
879 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
880 &(pMgmt->sNodeDBTable[0].wSuppRate),
881 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
882 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
883);
884 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
Teodora Baluta18278772013-11-11 19:27:05 +0200885 netdev_dbg(pDevice->dev,
886 "BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",
887 pMgmt->sNodeDBTable[0].wTxDataRate);
Joe Perchese1c77572013-03-18 10:44:39 -0700888 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
Forest Bond5449c682009-04-25 10:30:44 -0400889};
890
Forest Bond5449c682009-04-25 10:30:44 -0400891/*+
892 *
893 * Routine Description:
894 *
895 *
896 * Second call back function to update Node DB info & AP link status
897 *
898 *
899 * Return Value:
900 * none.
901 *
Joe Perchese1c77572013-03-18 10:44:39 -0700902 -*/
Teodora Baluta38395642013-11-09 01:00:00 +0200903/* 2008-4-14 <add> by chester for led issue */
Joe Perchese1c77572013-03-18 10:44:39 -0700904#ifdef FOR_LED_ON_NOTEBOOK
905bool cc = false;
Charles Clémentb6e95cd2010-06-02 09:52:01 -0700906unsigned int status;
Forest Bond5449c682009-04-25 10:30:44 -0400907#endif
Charles Clément6b35b7b2010-05-07 12:30:19 -0700908void
Forest Bond5449c682009-04-25 10:30:44 -0400909BSSvSecondCallBack(
Joe Perchese1c77572013-03-18 10:44:39 -0700910 void *hDeviceContext
911)
Forest Bond5449c682009-04-25 10:30:44 -0400912{
Joe Perchese1c77572013-03-18 10:44:39 -0700913 PSDevice pDevice = (PSDevice)hDeviceContext;
914 PSMgmtObject pMgmt = pDevice->pMgmt;
915 unsigned int ii;
916 PWLAN_IE_SSID pItemSSID, pCurrSSID;
917 unsigned int uSleepySTACnt = 0;
918 unsigned int uNonShortSlotSTACnt = 0;
919 unsigned int uLongPreambleSTACnt = 0;
Teodora Baluta38395642013-11-09 01:00:00 +0200920 viawget_wpa_header *wpahdr; /* DavidWang */
Forest Bond5449c682009-04-25 10:30:44 -0400921
Joe Perchese1c77572013-03-18 10:44:39 -0700922 spin_lock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400923
Joe Perchese1c77572013-03-18 10:44:39 -0700924 pDevice->uAssocCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400925
Joe Perchese1c77572013-03-18 10:44:39 -0700926 pDevice->byERPFlag &=
927 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
Teodora Baluta38395642013-11-09 01:00:00 +0200928 /* 2008-4-14 <add> by chester for led issue */
Forest Bond5449c682009-04-25 10:30:44 -0400929#ifdef FOR_LED_ON_NOTEBOOK
Joe Perchese1c77572013-03-18 10:44:39 -0700930 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200931 if (((!(pDevice->byGPIO & GPIO0_DATA) && (!pDevice->bHWRadioOff)) ||
932 ((pDevice->byGPIO & GPIO0_DATA) && pDevice->bHWRadioOff)) &&
933 (!cc)) {
Joe Perchese1c77572013-03-18 10:44:39 -0700934 cc = true;
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200935 } else if (cc) {
936 if (pDevice->bHWRadioOff) {
Teodora Baluta938db282013-11-09 01:00:03 +0200937 if (!(pDevice->byGPIO & GPIO0_DATA)) {
Teodora Balutab4f66ad2013-11-09 01:00:02 +0200938 if (status == 1)
939 goto start;
Joe Perchese1c77572013-03-18 10:44:39 -0700940 status = 1;
941 CARDbRadioPowerOff(pDevice);
942 pMgmt->sNodeDBTable[0].bActive = false;
943 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
944 pMgmt->eCurrState = WMAC_STATE_IDLE;
Joe Perchese1c77572013-03-18 10:44:39 -0700945 pDevice->bLinkPass = false;
Forest Bond5449c682009-04-25 10:30:44 -0400946
Joe Perchese1c77572013-03-18 10:44:39 -0700947 }
Teodora Baluta938db282013-11-09 01:00:03 +0200948 if (pDevice->byGPIO & GPIO0_DATA) {
Teodora Balutab4f66ad2013-11-09 01:00:02 +0200949 if (status == 2)
950 goto start;
Joe Perchese1c77572013-03-18 10:44:39 -0700951 status = 2;
952 CARDbRadioPowerOn(pDevice);
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700953 }
954 } else {
Teodora Baluta938db282013-11-09 01:00:03 +0200955 if (pDevice->byGPIO & GPIO0_DATA) {
Teodora Balutab4f66ad2013-11-09 01:00:02 +0200956 if (status == 3)
957 goto start;
Joe Perchese1c77572013-03-18 10:44:39 -0700958 status = 3;
959 CARDbRadioPowerOff(pDevice);
960 pMgmt->sNodeDBTable[0].bActive = false;
961 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
962 pMgmt->eCurrState = WMAC_STATE_IDLE;
Joe Perchese1c77572013-03-18 10:44:39 -0700963 pDevice->bLinkPass = false;
Forest Bond5449c682009-04-25 10:30:44 -0400964
Joe Perchese1c77572013-03-18 10:44:39 -0700965 }
Teodora Baluta938db282013-11-09 01:00:03 +0200966 if (!(pDevice->byGPIO & GPIO0_DATA)) {
Teodora Balutab4f66ad2013-11-09 01:00:02 +0200967 if (status == 4)
968 goto start;
Joe Perchese1c77572013-03-18 10:44:39 -0700969 status = 4;
970 CARDbRadioPowerOn(pDevice);
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700971 }
972 }
Joe Perchese1c77572013-03-18 10:44:39 -0700973 }
Forest Bond5449c682009-04-25 10:30:44 -0400974start:
975#endif
976
Joe Perchese1c77572013-03-18 10:44:39 -0700977 if (pDevice->wUseProtectCntDown > 0) {
978 pDevice->wUseProtectCntDown--;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700979 } else {
Teodora Baluta38395642013-11-09 01:00:00 +0200980 /* disable protect mode */
Joe Perchese1c77572013-03-18 10:44:39 -0700981 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
982 }
Forest Bond5449c682009-04-25 10:30:44 -0400983
Joe Perchese1c77572013-03-18 10:44:39 -0700984 {
985 pDevice->byReAssocCount++;
Teodora Baluta38395642013-11-09 01:00:00 +0200986 /* 10 sec timeout */
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200987 if ((pDevice->byReAssocCount > 10) && (!pDevice->bLinkPass)) {
Teodora Baluta18278772013-11-11 19:27:05 +0200988 netdev_info(pDevice->dev, "Re-association timeout!!!\n");
Joe Perchese1c77572013-03-18 10:44:39 -0700989 pDevice->byReAssocCount = 0;
990#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
Joe Perchese1c77572013-03-18 10:44:39 -0700991 {
992 union iwreq_data wrqu;
993 memset(&wrqu, 0, sizeof(wrqu));
994 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
995 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
996 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
997 }
998#endif
Teodora Baluta2b0c2a42013-11-11 19:27:07 +0200999 } else if (pDevice->bLinkPass)
Joe Perchese1c77572013-03-18 10:44:39 -07001000 pDevice->byReAssocCount = 0;
1001 }
Forest Bond5449c682009-04-25 10:30:44 -04001002
1003#ifdef Calcu_LinkQual
Joe Perchese1c77572013-03-18 10:44:39 -07001004 s_uCalculateLinkQual((void *)pDevice);
Forest Bond5449c682009-04-25 10:30:44 -04001005#endif
1006
Joe Perchese1c77572013-03-18 10:44:39 -07001007 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
Joe Perchese1c77572013-03-18 10:44:39 -07001008 if (pMgmt->sNodeDBTable[ii].bActive) {
Teodora Baluta38395642013-11-09 01:00:00 +02001009 /* increase in-activity counter */
Joe Perchese1c77572013-03-18 10:44:39 -07001010 pMgmt->sNodeDBTable[ii].uInActiveCount++;
Forest Bond5449c682009-04-25 10:30:44 -04001011
Joe Perchese1c77572013-03-18 10:44:39 -07001012 if (ii > 0) {
1013 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1014 BSSvRemoveOneNode(pDevice, ii);
1015 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1016 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1017 continue;
1018 }
Forest Bond5449c682009-04-25 10:30:44 -04001019
Joe Perchese1c77572013-03-18 10:44:39 -07001020 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
Joe Perchese1c77572013-03-18 10:44:39 -07001021 pDevice->uAssocCount++;
Forest Bond5449c682009-04-25 10:30:44 -04001022
Teodora Baluta38395642013-11-09 01:00:00 +02001023 /* check if Non ERP exist */
Joe Perchese1c77572013-03-18 10:44:39 -07001024 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1025 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1026 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1027 uLongPreambleSTACnt++;
1028 }
1029 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1030 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1031 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1032 }
1033 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1034 uNonShortSlotSTACnt++;
1035 }
1036 }
Forest Bond5449c682009-04-25 10:30:44 -04001037
Teodora Baluta38395642013-11-09 01:00:00 +02001038 /* check if any STA in PS mode */
Joe Perchese1c77572013-03-18 10:44:39 -07001039 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1040 uSleepySTACnt++;
Forest Bond5449c682009-04-25 10:30:44 -04001041
Joe Perchese1c77572013-03-18 10:44:39 -07001042 }
Forest Bond5449c682009-04-25 10:30:44 -04001043
Teodora Baluta38395642013-11-09 01:00:00 +02001044 /* rate fallback check */
Joe Perchese1c77572013-03-18 10:44:39 -07001045 if (!pDevice->bFixRate) {
Joe Perchese1c77572013-03-18 10:44:39 -07001046 if (ii > 0) {
Teodora Baluta38395642013-11-09 01:00:00 +02001047 /* ii = 0 for multicast node (AP & Adhoc) */
Joe Perchese1c77572013-03-18 10:44:39 -07001048 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001049 } else {
Teodora Baluta38395642013-11-09 01:00:00 +02001050 /* ii = 0 reserved for unicast AP node (Infra STA) */
Joe Perchese1c77572013-03-18 10:44:39 -07001051 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
Teodora Baluta18278772013-11-11 19:27:05 +02001052 netdev_dbg(pDevice->dev,
1053 "SecondCallback:Before:TxDataRate is %d\n",
1054 pMgmt->sNodeDBTable[0].wTxDataRate);
Joe Perchese1c77572013-03-18 10:44:39 -07001055 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
Teodora Baluta18278772013-11-11 19:27:05 +02001056 netdev_dbg(pDevice->dev,
1057 "SecondCallback:After:TxDataRate is %d\n",
1058 pMgmt->sNodeDBTable[0].wTxDataRate);
Forest Bond5449c682009-04-25 10:30:44 -04001059
Joe Perchese1c77572013-03-18 10:44:39 -07001060 }
1061
1062 }
1063
Teodora Baluta38395642013-11-09 01:00:00 +02001064 /* check if pending PS queue */
Joe Perchese1c77572013-03-18 10:44:39 -07001065 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
Teodora Balutaa7772892013-11-11 19:27:06 +02001066 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending\n",
Joe Perchese1c77572013-03-18 10:44:39 -07001067 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1068 if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1069 BSSvRemoveOneNode(pDevice, ii);
Teodora Balutaa7772892013-11-11 19:27:06 +02001070 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove\n", ii);
Joe Perchese1c77572013-03-18 10:44:39 -07001071 continue;
1072 }
1073 }
Forest Bond5449c682009-04-25 10:30:44 -04001074 }
1075
Joe Perchese1c77572013-03-18 10:44:39 -07001076 }
Forest Bond5449c682009-04-25 10:30:44 -04001077
Joe Perchese1c77572013-03-18 10:44:39 -07001078 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
Teodora Baluta38395642013-11-09 01:00:00 +02001079 /* on/off protect mode */
Joe Perchese1c77572013-03-18 10:44:39 -07001080 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1081 if (!pDevice->bProtectMode) {
1082 MACvEnableProtectMD(pDevice->PortOffset);
1083 pDevice->bProtectMode = true;
1084 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001085 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001086 if (pDevice->bProtectMode) {
1087 MACvDisableProtectMD(pDevice->PortOffset);
1088 pDevice->bProtectMode = false;
1089 }
1090 }
Teodora Baluta38395642013-11-09 01:00:00 +02001091 /* on/off short slot time */
Forest Bond5449c682009-04-25 10:30:44 -04001092
Joe Perchese1c77572013-03-18 10:44:39 -07001093 if (uNonShortSlotSTACnt > 0) {
1094 if (pDevice->bShortSlotTime) {
1095 pDevice->bShortSlotTime = false;
1096 BBvSetShortSlotTime(pDevice);
1097 vUpdateIFS((void *)pDevice);
1098 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001099 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001100 if (!pDevice->bShortSlotTime) {
1101 pDevice->bShortSlotTime = true;
1102 BBvSetShortSlotTime(pDevice);
1103 vUpdateIFS((void *)pDevice);
1104 }
1105 }
Forest Bond5449c682009-04-25 10:30:44 -04001106
Teodora Baluta38395642013-11-09 01:00:00 +02001107 /* on/off barker long preamble mode */
Forest Bond5449c682009-04-25 10:30:44 -04001108
Joe Perchese1c77572013-03-18 10:44:39 -07001109 if (uLongPreambleSTACnt > 0) {
1110 if (!pDevice->bBarkerPreambleMd) {
1111 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1112 pDevice->bBarkerPreambleMd = true;
1113 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001114 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001115 if (pDevice->bBarkerPreambleMd) {
1116 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1117 pDevice->bBarkerPreambleMd = false;
1118 }
1119 }
Forest Bond5449c682009-04-25 10:30:44 -04001120
Joe Perchese1c77572013-03-18 10:44:39 -07001121 }
Forest Bond5449c682009-04-25 10:30:44 -04001122
Teodora Baluta38395642013-11-09 01:00:00 +02001123 /* check if any STA in PS mode, enable DTIM multicast deliver */
Joe Perchese1c77572013-03-18 10:44:39 -07001124 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1125 if (uSleepySTACnt > 0)
1126 pMgmt->sNodeDBTable[0].bPSEnable = true;
1127 else
1128 pMgmt->sNodeDBTable[0].bPSEnable = false;
1129 }
Forest Bond5449c682009-04-25 10:30:44 -04001130
Joe Perchese1c77572013-03-18 10:44:39 -07001131 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1132 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
Jim Lieb612822f2009-08-12 14:54:03 -07001133
Joe Perchese1c77572013-03-18 10:44:39 -07001134 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1135 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
Teodora Baluta38395642013-11-09 01:00:00 +02001136 /* assoc with BSS */
1137 if (pMgmt->sNodeDBTable[0].bActive) {
Teodora Baluta347a0472013-11-09 01:00:01 +02001138 if (pDevice->bUpdateBBVGA)
Joe Perchese1c77572013-03-18 10:44:39 -07001139 s_vCheckPreEDThreshold((void *)pDevice);
Jim Lieb612822f2009-08-12 14:54:03 -07001140
Joe Perchese1c77572013-03-18 10:44:39 -07001141 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1142 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
1143 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1144 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1145 }
Forest Bond5449c682009-04-25 10:30:44 -04001146
Joe Perchese1c77572013-03-18 10:44:39 -07001147 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1148 pMgmt->sNodeDBTable[0].bActive = false;
1149 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1150 pMgmt->eCurrState = WMAC_STATE_IDLE;
1151 netif_stop_queue(pDevice->dev);
1152 pDevice->bLinkPass = false;
1153 pDevice->bRoaming = true;
1154 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1155 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1156 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1157 wpahdr->type = VIAWGET_DISASSOC_MSG;
1158 wpahdr->resp_ie_len = 0;
1159 wpahdr->req_ie_len = 0;
1160 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1161 pDevice->skb->dev = pDevice->wpadev;
1162 skb_reset_mac_header(pDevice->skb);
1163 pDevice->skb->pkt_type = PACKET_HOST;
1164 pDevice->skb->protocol = htons(ETH_P_802_2);
1165 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1166 netif_rx(pDevice->skb);
1167 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1168 }
1169#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
Joe Perchese1c77572013-03-18 10:44:39 -07001170 {
1171 union iwreq_data wrqu;
1172 memset(&wrqu, 0, sizeof(wrqu));
1173 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1174 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1175 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1176 }
1177#endif
1178 }
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001179 } else if (pItemSSID->len != 0) {
Joe Perchese1c77572013-03-18 10:44:39 -07001180 if (pDevice->uAutoReConnectTime < 10) {
1181 pDevice->uAutoReConnectTime++;
1182#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
Teodora Baluta38395642013-11-09 01:00:00 +02001183 /*
1184 * network manager support need not do
1185 * Roaming scan???
1186 */
Teodora Baluta2b0c2a42013-11-11 19:27:07 +02001187 if (pDevice->bWPASuppWextEnabled)
Joe Perchese1c77572013-03-18 10:44:39 -07001188 pDevice->uAutoReConnectTime = 0;
1189#endif
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001190 } else {
Teodora Baluta38395642013-11-09 01:00:00 +02001191 /*
1192 * mike use old encryption status
1193 * for wpa reauthentication
1194 */
Joe Perchese1c77572013-03-18 10:44:39 -07001195 if (pDevice->bWPADEVUp)
1196 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
Jim Lieb612822f2009-08-12 14:54:03 -07001197
Joe Perchese1c77572013-03-18 10:44:39 -07001198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1199 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1200 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1201 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1202 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1203 pDevice->uAutoReConnectTime = 0;
1204 }
1205 }
1206 }
Forest Bond5449c682009-04-25 10:30:44 -04001207
Joe Perchese1c77572013-03-18 10:44:39 -07001208 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Teodora Baluta38395642013-11-09 01:00:00 +02001209 /* if adhoc started which essid is NULL string, rescanning */
Joe Perchese1c77572013-03-18 10:44:39 -07001210 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1211 if (pDevice->uAutoReConnectTime < 10) {
1212 pDevice->uAutoReConnectTime++;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001213 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001214 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1215 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1216 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1217 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1218 pDevice->uAutoReConnectTime = 0;
Teodora Baluta88cc8502013-11-10 17:12:45 +02001219 }
Joe Perchese1c77572013-03-18 10:44:39 -07001220 }
1221 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
Teodora Baluta347a0472013-11-09 01:00:01 +02001222 if (pDevice->bUpdateBBVGA)
Joe Perchese1c77572013-03-18 10:44:39 -07001223 s_vCheckPreEDThreshold((void *)pDevice);
Joe Perchese1c77572013-03-18 10:44:39 -07001224 if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
1225 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1226 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1227 pMgmt->eCurrState = WMAC_STATE_STARTED;
1228 netif_stop_queue(pDevice->dev);
1229 pDevice->bLinkPass = false;
1230 }
1231 }
1232 }
Forest Bond5449c682009-04-25 10:30:44 -04001233
Joe Perchese1c77572013-03-18 10:44:39 -07001234 spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -04001235
Joe Perchese1c77572013-03-18 10:44:39 -07001236 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1237 add_timer(&pMgmt->sTimerSecondCallback);
1238 return;
Forest Bond5449c682009-04-25 10:30:44 -04001239}
1240
Forest Bond5449c682009-04-25 10:30:44 -04001241/*+
1242 *
1243 * Routine Description:
1244 *
1245 *
1246 * Update Tx attemps, Tx failure counter in Node DB
1247 *
1248 *
1249 * Return Value:
1250 * none.
1251 *
Joe Perchese1c77572013-03-18 10:44:39 -07001252 -*/
Forest Bond5449c682009-04-25 10:30:44 -04001253
Charles Clément6b35b7b2010-05-07 12:30:19 -07001254void
Forest Bond5449c682009-04-25 10:30:44 -04001255BSSvUpdateNodeTxCounter(
Joe Perchese1c77572013-03-18 10:44:39 -07001256 void *hDeviceContext,
1257 unsigned char byTsr0,
1258 unsigned char byTsr1,
1259 unsigned char *pbyBuffer,
1260 unsigned int uFIFOHeaderSize
1261)
Forest Bond5449c682009-04-25 10:30:44 -04001262{
Joe Perchese1c77572013-03-18 10:44:39 -07001263 PSDevice pDevice = (PSDevice)hDeviceContext;
1264 PSMgmtObject pMgmt = pDevice->pMgmt;
1265 unsigned int uNodeIndex = 0;
1266 unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1267 PSTxBufHead pTxBufHead;
1268 PS802_11Header pMACHeader;
1269 unsigned short wRate;
1270 unsigned short wFallBackRate = RATE_1M;
1271 unsigned char byFallBack;
1272 unsigned int ii;
Joe Perchese1c77572013-03-18 10:44:39 -07001273 pTxBufHead = (PSTxBufHead) pbyBuffer;
Teodora Baluta347a0472013-11-09 01:00:01 +02001274 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0)
Joe Perchese1c77572013-03-18 10:44:39 -07001275 byFallBack = AUTO_FB_0;
Teodora Baluta347a0472013-11-09 01:00:01 +02001276 else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1)
Joe Perchese1c77572013-03-18 10:44:39 -07001277 byFallBack = AUTO_FB_1;
Teodora Baluta347a0472013-11-09 01:00:01 +02001278 else
Joe Perchese1c77572013-03-18 10:44:39 -07001279 byFallBack = AUTO_FB_NONE;
Teodora Baluta38395642013-11-09 01:00:00 +02001280 wRate = pTxBufHead->wReserved;
Forest Bond5449c682009-04-25 10:30:44 -04001281
Teodora Baluta38395642013-11-09 01:00:00 +02001282 /* Only Unicast using support rates */
Joe Perchese1c77572013-03-18 10:44:39 -07001283 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1284 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1285 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1286 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1287 if ((byTsr1 & TSR1_TERR) == 0) {
Teodora Baluta38395642013-11-09 01:00:00 +02001288 /* transmit success, TxAttempts at least plus one */
Joe Perchese1c77572013-03-18 10:44:39 -07001289 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1290 if ((byFallBack == AUTO_FB_NONE) ||
1291 (wRate < RATE_18M)) {
1292 wFallBackRate = wRate;
1293 } else if (byFallBack == AUTO_FB_0) {
Joe Perchese1c77572013-03-18 10:44:39 -07001294 if (byTxRetry < 5)
Joe Perchese1c77572013-03-18 10:44:39 -07001295 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
Joe Perchese1c77572013-03-18 10:44:39 -07001296 else
1297 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
Joe Perchese1c77572013-03-18 10:44:39 -07001298 } else if (byFallBack == AUTO_FB_1) {
1299 if (byTxRetry < 5)
1300 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1301 else
1302 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
Forest Bond5449c682009-04-25 10:30:44 -04001303 }
Joe Perchese1c77572013-03-18 10:44:39 -07001304 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1305 } else {
1306 pMgmt->sNodeDBTable[0].uTxFailures++;
1307 }
1308 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1309 if (byTxRetry != 0) {
1310 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
1311 if ((byFallBack == AUTO_FB_NONE) ||
1312 (wRate < RATE_18M)) {
1313 pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
1314 } else if (byFallBack == AUTO_FB_0) {
Teodora Baluta938db282013-11-09 01:00:03 +02001315 for (ii = 0; ii < byTxRetry; ii++) {
Teodora Baluta347a0472013-11-09 01:00:01 +02001316 if (ii < 5)
Joe Perchese1c77572013-03-18 10:44:39 -07001317 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
Teodora Baluta347a0472013-11-09 01:00:01 +02001318 else
Joe Perchese1c77572013-03-18 10:44:39 -07001319 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
Forest Bond5449c682009-04-25 10:30:44 -04001320 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
Joe Perchese1c77572013-03-18 10:44:39 -07001321 }
1322 } else if (byFallBack == AUTO_FB_1) {
1323 for (ii = 0; ii < byTxRetry; ii++) {
1324 if (ii < 5)
1325 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1326 else
1327 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1328 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1329 }
1330 }
1331 }
1332 }
Forest Bond5449c682009-04-25 10:30:44 -04001333
Joe Perchese1c77572013-03-18 10:44:39 -07001334 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1335 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
Joe Perchese1c77572013-03-18 10:44:39 -07001336 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
Forest Bond5449c682009-04-25 10:30:44 -04001337
Joe Perchese1c77572013-03-18 10:44:39 -07001338 if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
1339 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1340 if ((byTsr1 & TSR1_TERR) == 0) {
Teodora Baluta38395642013-11-09 01:00:00 +02001341 /* transmit success, TxAttempts at least plus one */
Joe Perchese1c77572013-03-18 10:44:39 -07001342 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1343 if ((byFallBack == AUTO_FB_NONE) ||
1344 (wRate < RATE_18M)) {
1345 wFallBackRate = wRate;
1346 } else if (byFallBack == AUTO_FB_0) {
1347 if (byTxRetry < 5)
1348 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1349 else
1350 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1351 } else if (byFallBack == AUTO_FB_1) {
1352 if (byTxRetry < 5)
1353 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1354 else
1355 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1356 }
1357 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1358 } else {
1359 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
1360 }
1361 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1362 if (byTxRetry != 0) {
1363 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
1364 if ((byFallBack == AUTO_FB_NONE) ||
1365 (wRate < RATE_18M)) {
1366 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
1367 } else if (byFallBack == AUTO_FB_0) {
1368 for (ii = 0; ii < byTxRetry; ii++) {
1369 if (ii < 5)
1370 wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
1371 else
1372 wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
1373 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1374 }
1375 } else if (byFallBack == AUTO_FB_1) {
1376 for (ii = 0; ii < byTxRetry; ii++) {
1377 if (ii < 5)
1378 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1379 else
1380 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1381 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1382 }
1383 }
1384 }
1385 }
1386 }
1387 }
Forest Bond5449c682009-04-25 10:30:44 -04001388
Joe Perchese1c77572013-03-18 10:44:39 -07001389 return;
Forest Bond5449c682009-04-25 10:30:44 -04001390}
1391
Forest Bond5449c682009-04-25 10:30:44 -04001392/*+
1393 *
1394 * Routine Description:
1395 * Clear Nodes & skb in DB Table
1396 *
1397 *
1398 * Parameters:
1399 * In:
1400 * hDeviceContext - The adapter context.
1401 * uStartIndex - starting index
1402 * Out:
1403 * none
1404 *
1405 * Return Value:
1406 * None.
1407 *
Joe Perchese1c77572013-03-18 10:44:39 -07001408 -*/
Forest Bond5449c682009-04-25 10:30:44 -04001409
Charles Clément6b35b7b2010-05-07 12:30:19 -07001410void
Forest Bond5449c682009-04-25 10:30:44 -04001411BSSvClearNodeDBTable(
Joe Perchese1c77572013-03-18 10:44:39 -07001412 void *hDeviceContext,
1413 unsigned int uStartIndex
1414)
Forest Bond5449c682009-04-25 10:30:44 -04001415
1416{
Joe Perchese1c77572013-03-18 10:44:39 -07001417 PSDevice pDevice = (PSDevice)hDeviceContext;
1418 PSMgmtObject pMgmt = pDevice->pMgmt;
1419 struct sk_buff *skb;
1420 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001421
Joe Perchese1c77572013-03-18 10:44:39 -07001422 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1423 if (pMgmt->sNodeDBTable[ii].bActive) {
Teodora Baluta38395642013-11-09 01:00:00 +02001424 /* check if sTxPSQueue has been initial */
Joe Perchese1c77572013-03-18 10:44:39 -07001425 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1426 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
1427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1428 dev_kfree_skb(skb);
1429 }
1430 }
1431 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1432 }
1433 }
Forest Bond5449c682009-04-25 10:30:44 -04001434
Joe Perchese1c77572013-03-18 10:44:39 -07001435 return;
Forest Bond5449c682009-04-25 10:30:44 -04001436};
1437
Charles Clément6b35b7b2010-05-07 12:30:19 -07001438void s_vCheckSensitivity(
Joe Perchese1c77572013-03-18 10:44:39 -07001439 void *hDeviceContext
1440)
Forest Bond5449c682009-04-25 10:30:44 -04001441{
Joe Perchese1c77572013-03-18 10:44:39 -07001442 PSDevice pDevice = (PSDevice)hDeviceContext;
1443 PKnownBSS pBSSList = NULL;
1444 PSMgmtObject pMgmt = pDevice->pMgmt;
1445 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001446
Joe Perchese1c77572013-03-18 10:44:39 -07001447 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1448 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1449 return;
1450 }
Forest Bond5449c682009-04-25 10:30:44 -04001451
Joe Perchese1c77572013-03-18 10:44:39 -07001452 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1453 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1454 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1455 if (pBSSList != NULL) {
Teodora Baluta38395642013-11-09 01:00:00 +02001456 /* Update BB Reg if RSSI is too strong */
Joe Perchese1c77572013-03-18 10:44:39 -07001457 long LocalldBmAverage = 0;
1458 long uNumofdBm = 0;
1459 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1460 if (pBSSList->ldBmAverage[ii] != 0) {
1461 uNumofdBm++;
1462 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1463 }
1464 }
1465 if (uNumofdBm > 0) {
1466 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1467 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1469 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1470 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1471 break;
1472 }
1473 }
1474 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1475 pDevice->uBBVGADiffCount++;
1476 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1477 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1478 } else {
1479 pDevice->uBBVGADiffCount = 0;
1480 }
1481 }
1482 }
1483 }
Forest Bond5449c682009-04-25 10:30:44 -04001484}
1485
Charles Clément6b35b7b2010-05-07 12:30:19 -07001486void
Joe Perchese1c77572013-03-18 10:44:39 -07001487BSSvClearAnyBSSJoinRecord(
1488 void *hDeviceContext
1489)
Forest Bond5449c682009-04-25 10:30:44 -04001490{
Joe Perchese1c77572013-03-18 10:44:39 -07001491 PSDevice pDevice = (PSDevice)hDeviceContext;
1492 PSMgmtObject pMgmt = pDevice->pMgmt;
1493 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001494
Teodora Baluta347a0472013-11-09 01:00:01 +02001495 for (ii = 0; ii < MAX_BSS_NUM; ii++)
Joe Perchese1c77572013-03-18 10:44:39 -07001496 pMgmt->sBSSList[ii].bSelected = false;
Joe Perchese1c77572013-03-18 10:44:39 -07001497 return;
Forest Bond5449c682009-04-25 10:30:44 -04001498}
1499
1500#ifdef Calcu_LinkQual
Charles Clément6b35b7b2010-05-07 12:30:19 -07001501void s_uCalculateLinkQual(
Joe Perchese1c77572013-03-18 10:44:39 -07001502 void *hDeviceContext
1503)
Forest Bond5449c682009-04-25 10:30:44 -04001504{
Joe Perchese1c77572013-03-18 10:44:39 -07001505 PSDevice pDevice = (PSDevice)hDeviceContext;
1506 unsigned long TxOkRatio, TxCnt;
1507 unsigned long RxOkRatio, RxCnt;
1508 unsigned long RssiRatio;
1509 long ldBm;
Forest Bond5449c682009-04-25 10:30:44 -04001510
Joe Perchese1c77572013-03-18 10:44:39 -07001511 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1512 pDevice->scStatistic.TxRetryOkCount +
1513 pDevice->scStatistic.TxFailCount;
1514 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1515 pDevice->scStatistic.RxOkCnt;
1516 TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1517 RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
Teodora Baluta38395642013-11-09 01:00:00 +02001518 /* decide link quality */
Teodora Baluta2b0c2a42013-11-11 19:27:07 +02001519 if (!pDevice->bLinkPass) {
Joe Perchese1c77572013-03-18 10:44:39 -07001520 pDevice->scStatistic.LinkQuality = 0;
1521 pDevice->scStatistic.SignalStren = 0;
Joe Perches5e0cc8a2013-03-18 20:55:37 -07001522 } else {
Joe Perchese1c77572013-03-18 10:44:39 -07001523 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
Teodora Baluta347a0472013-11-09 01:00:01 +02001524 if (-ldBm < 50)
Joe Perchese1c77572013-03-18 10:44:39 -07001525 RssiRatio = 4000;
Teodora Baluta347a0472013-11-09 01:00:01 +02001526 else if (-ldBm > 90)
Joe Perchese1c77572013-03-18 10:44:39 -07001527 RssiRatio = 0;
Teodora Baluta347a0472013-11-09 01:00:01 +02001528 else
Joe Perchese1c77572013-03-18 10:44:39 -07001529 RssiRatio = (40-(-ldBm-50))*4000/40;
Joe Perchese1c77572013-03-18 10:44:39 -07001530 pDevice->scStatistic.SignalStren = RssiRatio/40;
1531 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1532 }
1533 pDevice->scStatistic.RxFcsErrCnt = 0;
1534 pDevice->scStatistic.RxOkCnt = 0;
1535 pDevice->scStatistic.TxFailCount = 0;
1536 pDevice->scStatistic.TxNoRetryOkCount = 0;
1537 pDevice->scStatistic.TxRetryOkCount = 0;
1538 return;
Forest Bond5449c682009-04-25 10:30:44 -04001539}
1540#endif
1541
Charles Clément6b35b7b2010-05-07 12:30:19 -07001542void s_vCheckPreEDThreshold(
Joe Perchese1c77572013-03-18 10:44:39 -07001543 void *hDeviceContext
1544)
Forest Bond5449c682009-04-25 10:30:44 -04001545{
Joe Perchese1c77572013-03-18 10:44:39 -07001546 PSDevice pDevice = (PSDevice)hDeviceContext;
1547 PKnownBSS pBSSList = NULL;
1548 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
Forest Bond5449c682009-04-25 10:30:44 -04001549
Joe Perchese1c77572013-03-18 10:44:39 -07001550 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1551 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1552 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
Teodora Baluta347a0472013-11-09 01:00:01 +02001553 if (pBSSList != NULL)
Joe Perchese1c77572013-03-18 10:44:39 -07001554 pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
Joe Perchese1c77572013-03-18 10:44:39 -07001555 }
1556 return;
Forest Bond5449c682009-04-25 10:30:44 -04001557}