blob: 4d425e0c76d4c266f46c674968766e3d7e36fee6 [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 *
20 * File: vntwifi.c
21 *
22 * Purpose: export functions for vntwifi lib
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: feb. 2, 2005
31 *
32 */
33
Forest Bond5449c682009-04-25 10:30:44 -040034#include "vntwifi.h"
Forest Bond5449c682009-04-25 10:30:44 -040035#include "IEEE11h.h"
Forest Bond5449c682009-04-25 10:30:44 -040036#include "country.h"
Forest Bond5449c682009-04-25 10:30:44 -040037#include "device.h"
Forest Bond5449c682009-04-25 10:30:44 -040038#include "wmgr.h"
Forest Bond5449c682009-04-25 10:30:44 -040039#include "datarate.h"
Jim Lieba7ad3222009-08-12 14:54:09 -070040
Forest Bond5449c682009-04-25 10:30:44 -040041/*--------------------- Static Definitions -------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -040042
43/*--------------------- Static Classes ----------------------------*/
44
45/*--------------------- Static Variables --------------------------*/
46
47/*--------------------- Static Functions --------------------------*/
48
49/*--------------------- Export Variables --------------------------*/
50
51/*--------------------- Export Functions --------------------------*/
52
53/*+
54 *
55 * Description:
56 * Set Operation Mode
57 *
58 * Parameters:
59 * In:
60 * pMgmtHandle - pointer to management object
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070061 * eOPMode - Operation Mode
Forest Bond5449c682009-04-25 10:30:44 -040062 * Out:
63 * none
64 *
65 * Return Value: none
66 *
Joe Perchesd9d644e2013-03-18 10:45:08 -070067 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -070068void
Joe Perchesd9d644e2013-03-18 10:45:08 -070069VNTWIFIvSetOPMode(
70 void *pMgmtHandle,
71 WMAC_CONFIG_MODE eOPMode
72)
Forest Bond5449c682009-04-25 10:30:44 -040073{
Joe Perchesd9d644e2013-03-18 10:45:08 -070074 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -040075
Joe Perchesd9d644e2013-03-18 10:45:08 -070076 pMgmt->eConfigMode = eOPMode;
Forest Bond5449c682009-04-25 10:30:44 -040077}
78
Forest Bond5449c682009-04-25 10:30:44 -040079/*+
80 *
81 * Description:
82 * Set Operation Mode
83 *
84 * Parameters:
85 * In:
86 * pMgmtHandle - pointer to management object
87 * wBeaconPeriod - Beacon Period
88 * wATIMWindow - ATIM window
89 * uChannel - channel number
90 * Out:
91 * none
92 *
93 * Return Value: none
94 *
Joe Perchesd9d644e2013-03-18 10:45:08 -070095 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -070096void
Joe Perchesd9d644e2013-03-18 10:45:08 -070097VNTWIFIvSetIBSSParameter(
98 void *pMgmtHandle,
99 unsigned short wBeaconPeriod,
100 unsigned short wATIMWindow,
101 unsigned int uChannel
102)
Forest Bond5449c682009-04-25 10:30:44 -0400103{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700104 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400105
Joe Perchesd9d644e2013-03-18 10:45:08 -0700106 pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
107 pMgmt->wIBSSATIMWindow = wATIMWindow;
108 pMgmt->uIBSSChannel = uChannel;
Forest Bond5449c682009-04-25 10:30:44 -0400109}
110
111/*+
112 *
113 * Description:
114 * Get current SSID
115 *
116 * Parameters:
117 * In:
118 * pMgmtHandle - pointer to management object
119 * Out:
120 * none
121 *
122 * Return Value: current SSID pointer.
123 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700124 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400125PWLAN_IE_SSID
Joe Perchesd9d644e2013-03-18 10:45:08 -0700126VNTWIFIpGetCurrentSSID(
127 void *pMgmtHandle
128)
Forest Bond5449c682009-04-25 10:30:44 -0400129{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700130 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Guillaume Clement6b711272014-07-25 01:06:16 +0200131
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700132 return (PWLAN_IE_SSID) pMgmt->abyCurrSSID;
Forest Bond5449c682009-04-25 10:30:44 -0400133}
134
135/*+
136 *
137 * Description:
138 * Get current link channel
139 *
140 * Parameters:
141 * In:
142 * pMgmtHandle - pointer to management object
143 * Out:
144 * none
145 *
146 * Return Value: current Channel.
147 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700148 -*/
Charles Clémentb6e95cd2010-06-02 09:52:01 -0700149unsigned int
Joe Perchesd9d644e2013-03-18 10:45:08 -0700150VNTWIFIpGetCurrentChannel(
151 void *pMgmtHandle
152)
Forest Bond5449c682009-04-25 10:30:44 -0400153{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700154 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Guillaume Clement6b711272014-07-25 01:06:16 +0200155
Guido Martínezbc5cf652014-04-19 16:45:00 -0300156 if (pMgmtHandle != NULL)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700157 return pMgmt->uCurrChannel;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300158
Joe Perchesd9d644e2013-03-18 10:45:08 -0700159 return 0;
Forest Bond5449c682009-04-25 10:30:44 -0400160}
161
162/*+
163 *
164 * Description:
165 * Get current Assoc ID
166 *
167 * Parameters:
168 * In:
169 * pMgmtHandle - pointer to management object
170 * Out:
171 * none
172 *
173 * Return Value: current Assoc ID
174 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700175 -*/
Charles Clément2986db52010-06-24 11:02:26 -0700176unsigned short
Joe Perchesd9d644e2013-03-18 10:45:08 -0700177VNTWIFIwGetAssocID(
178 void *pMgmtHandle
179)
Forest Bond5449c682009-04-25 10:30:44 -0400180{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700181 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Guillaume Clement6b711272014-07-25 01:06:16 +0200182
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700183 return pMgmt->wCurrAID;
Forest Bond5449c682009-04-25 10:30:44 -0400184}
185
Forest Bond5449c682009-04-25 10:30:44 -0400186/*+
187 *
188 * Description:
189 * This routine return max support rate of IES
190 *
191 * Parameters:
192 * In:
193 * pSupportRateIEs
194 * pExtSupportRateIEs
195 *
196 * Out:
197 *
198 * Return Value: max support rate
199 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700200 -*/
Charles Clément3fc9b582010-06-24 11:02:27 -0700201unsigned char
Joe Perchesd9d644e2013-03-18 10:45:08 -0700202VNTWIFIbyGetMaxSupportRate(
203 PWLAN_IE_SUPP_RATES pSupportRateIEs,
204 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
205)
Forest Bond5449c682009-04-25 10:30:44 -0400206{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700207 unsigned char byMaxSupportRate = RATE_1M;
208 unsigned char bySupportRate = RATE_1M;
209 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400210
Joe Perchesd9d644e2013-03-18 10:45:08 -0700211 if (pSupportRateIEs) {
212 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
213 bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300214 if (bySupportRate > byMaxSupportRate)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700215 byMaxSupportRate = bySupportRate;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300216
Joe Perchesd9d644e2013-03-18 10:45:08 -0700217 }
218 }
219 if (pExtSupportRateIEs) {
220 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
221 bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300222 if (bySupportRate > byMaxSupportRate)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700223 byMaxSupportRate = bySupportRate;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300224
Joe Perchesd9d644e2013-03-18 10:45:08 -0700225 }
226 }
Forest Bond5449c682009-04-25 10:30:44 -0400227
Joe Perchesd9d644e2013-03-18 10:45:08 -0700228 return byMaxSupportRate;
Forest Bond5449c682009-04-25 10:30:44 -0400229}
230
231/*+
232 *
233 * Description:
234 * This routine return data rate of ACK packtet
235 *
236 * Parameters:
237 * In:
238 * byRxDataRate
239 * pSupportRateIEs
240 * pExtSupportRateIEs
241 *
242 * Out:
243 *
244 * Return Value: max support rate
245 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700246 -*/
Charles Clément3fc9b582010-06-24 11:02:27 -0700247unsigned char
Joe Perchesd9d644e2013-03-18 10:45:08 -0700248VNTWIFIbyGetACKTxRate(
249 unsigned char byRxDataRate,
250 PWLAN_IE_SUPP_RATES pSupportRateIEs,
251 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
252)
Forest Bond5449c682009-04-25 10:30:44 -0400253{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700254 unsigned char byMaxAckRate;
255 unsigned char byBasicRate;
256 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400257
Joe Perchesd9d644e2013-03-18 10:45:08 -0700258 if (byRxDataRate <= RATE_11M) {
259 byMaxAckRate = RATE_1M;
260 } else {
Merlin Chlosta5c3ddb32014-06-19 19:59:32 +0200261 /* 24M is mandatory for 802.11a and 802.11g */
Joe Perchesd9d644e2013-03-18 10:45:08 -0700262 byMaxAckRate = RATE_24M;
263 }
264 if (pSupportRateIEs) {
265 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
266 if (pSupportRateIEs->abyRates[ii] & 0x80) {
267 byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
268 if ((byBasicRate <= byRxDataRate) &&
269 (byBasicRate > byMaxAckRate)) {
270 byMaxAckRate = byBasicRate;
271 }
272 }
273 }
274 }
275 if (pExtSupportRateIEs) {
276 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
277 if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
278 byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
279 if ((byBasicRate <= byRxDataRate) &&
280 (byBasicRate > byMaxAckRate)) {
281 byMaxAckRate = byBasicRate;
282 }
283 }
284 }
285 }
Forest Bond5449c682009-04-25 10:30:44 -0400286
Joe Perchesd9d644e2013-03-18 10:45:08 -0700287 return byMaxAckRate;
Forest Bond5449c682009-04-25 10:30:44 -0400288}
289
290/*+
291 *
292 * Description:
293 * Set Authentication Mode
294 *
295 * Parameters:
296 * In:
297 * pMgmtHandle - pointer to management object
298 * eAuthMode - Authentication mode
299 * Out:
300 * none
301 *
302 * Return Value: none
303 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700304 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700305void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700306VNTWIFIvSetAuthenticationMode(
307 void *pMgmtHandle,
308 WMAC_AUTHENTICATION_MODE eAuthMode
309)
Forest Bond5449c682009-04-25 10:30:44 -0400310{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700311 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400312
Joe Perchesd9d644e2013-03-18 10:45:08 -0700313 pMgmt->eAuthenMode = eAuthMode;
314 if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
315 (eAuthMode == WMAC_AUTH_AUTO)) {
316 pMgmt->bShareKeyAlgorithm = true;
317 } else {
318 pMgmt->bShareKeyAlgorithm = false;
319 }
Forest Bond5449c682009-04-25 10:30:44 -0400320}
321
322/*+
323 *
324 * Description:
325 * Set Encryption Mode
326 *
327 * Parameters:
328 * In:
329 * pMgmtHandle - pointer to management object
330 * eAuthMode - Authentication mode
331 * Out:
332 * none
333 *
334 * Return Value: none
335 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700336 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700337void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700338VNTWIFIvSetEncryptionMode(
339 void *pMgmtHandle,
340 WMAC_ENCRYPTION_MODE eEncryptionMode
341)
Forest Bond5449c682009-04-25 10:30:44 -0400342{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700343 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400344
Joe Perchesd9d644e2013-03-18 10:45:08 -0700345 pMgmt->eEncryptionMode = eEncryptionMode;
346 if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
347 (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
348 (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled)) {
349 pMgmt->bPrivacyInvoked = true;
350 } else {
351 pMgmt->bPrivacyInvoked = false;
352 }
Forest Bond5449c682009-04-25 10:30:44 -0400353}
354
Charles Clément7b6a0012010-08-01 17:15:50 +0200355bool
Joe Perchesd9d644e2013-03-18 10:45:08 -0700356VNTWIFIbConfigPhyMode(
357 void *pMgmtHandle,
358 CARD_PHY_TYPE ePhyType
359)
Forest Bond5449c682009-04-25 10:30:44 -0400360{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700361 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400362
Joe Perchesd9d644e2013-03-18 10:45:08 -0700363 if ((ePhyType != PHY_TYPE_AUTO) &&
364 (ePhyType != pMgmt->eCurrentPHYMode)) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300365 if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL) == true)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700366 pMgmt->eCurrentPHYMode = ePhyType;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300367 else
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700368 return false;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700369 }
370 pMgmt->eConfigPHYMode = ePhyType;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700371 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400372}
373
Charles Clément6b35b7b2010-05-07 12:30:19 -0700374void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700375VNTWIFIbGetConfigPhyMode(
376 void *pMgmtHandle,
377 void *pePhyType
378)
Forest Bond5449c682009-04-25 10:30:44 -0400379{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700380 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400381
Guido Martínezbc5cf652014-04-19 16:45:00 -0300382 if ((pMgmt != NULL) && (pePhyType != NULL))
Joe Perchesd9d644e2013-03-18 10:45:08 -0700383 *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
Forest Bond5449c682009-04-25 10:30:44 -0400384}
385
386/*+
387 *
388 * Description:
389 * Clear BSS List Database except current assoc BSS
390 *
391 * Parameters:
392 * In:
393 * pMgmtHandle - Management Object structure
394 * bLinkPass - Current Link status
395 * Out:
396 *
397 * Return Value: None.
398 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700399 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400400
Forest Bond5449c682009-04-25 10:30:44 -0400401/*+
402 *
403 * Description:
404 * Query BSS List in management database
405 *
406 * Parameters:
407 * In:
408 * pMgmtHandle - Management Object structure
409 * Out:
410 * puBSSCount - BSS count
411 * pvFirstBSS - pointer to first BSS
412 *
413 * Return Value: None.
414 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700415 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400416
Charles Clément6b35b7b2010-05-07 12:30:19 -0700417void
Charles Clémentfe4f34b2010-06-25 10:48:53 -0700418VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount, void **pvFirstBSS)
Forest Bond5449c682009-04-25 10:30:44 -0400419{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700420 unsigned int ii = 0;
421 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
422 PKnownBSS pBSS = NULL;
423 unsigned int uCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400424
Joe Perchesd9d644e2013-03-18 10:45:08 -0700425 *pvFirstBSS = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400426
Joe Perchesd9d644e2013-03-18 10:45:08 -0700427 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
428 pBSS = &(pMgmt->sBSSList[ii]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300429 if (!pBSS->bActive)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700430 continue;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300431
432 if (*pvFirstBSS == NULL)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700433 *pvFirstBSS = &(pMgmt->sBSSList[ii]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300434
Joe Perchesd9d644e2013-03-18 10:45:08 -0700435 uCount++;
436 }
437 *puBSSCount = uCount;
Forest Bond5449c682009-04-25 10:30:44 -0400438}
439
Charles Clément6b35b7b2010-05-07 12:30:19 -0700440void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700441VNTWIFIvGetNextBSS(
442 void *pMgmtHandle,
443 void *pvCurrentBSS,
444 void **pvNextBSS
445)
Forest Bond5449c682009-04-25 10:30:44 -0400446{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700447 PKnownBSS pBSS = (PKnownBSS) pvCurrentBSS;
448 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400449
Joe Perchesd9d644e2013-03-18 10:45:08 -0700450 *pvNextBSS = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400451
Joe Perchesd9d644e2013-03-18 10:45:08 -0700452 while (*pvNextBSS == NULL) {
453 pBSS++;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300454 if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM]))
Joe Perchesd9d644e2013-03-18 10:45:08 -0700455 return;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300456
Joe Perchesd9d644e2013-03-18 10:45:08 -0700457 if (pBSS->bActive == true) {
458 *pvNextBSS = pBSS;
459 return;
460 }
461 }
Forest Bond5449c682009-04-25 10:30:44 -0400462}
463
Forest Bond5449c682009-04-25 10:30:44 -0400464/*+
465 *
466 * Description:
467 * Update Tx attemps, Tx failure counter in Node DB
468 *
469 * In:
470 * Out:
471 * none
472 *
473 * Return Value: none
474 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700475 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700476void
Forest Bond5449c682009-04-25 10:30:44 -0400477VNTWIFIvUpdateNodeTxCounter(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700478 void *pMgmtHandle,
479 unsigned char *pbyDestAddress,
480 bool bTxOk,
481 unsigned short wRate,
482 unsigned char *pbyTxFailCount
483)
Forest Bond5449c682009-04-25 10:30:44 -0400484{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700485 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
486 unsigned int uNodeIndex = 0;
487 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400488
Joe Perchesd9d644e2013-03-18 10:45:08 -0700489 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
490 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300491 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == false)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700492 return;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700493 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300494
Joe Perchesd9d644e2013-03-18 10:45:08 -0700495 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
Teodora Baluta1208f14a2013-11-10 17:12:42 +0200496 if (bTxOk) {
Merlin Chlosta5c3ddb32014-06-19 19:59:32 +0200497 /* transmit success, TxAttempts at least plus one */
Joe Perchesd9d644e2013-03-18 10:45:08 -0700498 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
499 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
500 } else {
501 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
502 }
503 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
Guido Martínezbc5cf652014-04-19 16:45:00 -0300504 for (ii = 0; ii < MAX_RATE; ii++)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700505 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
Forest Bond5449c682009-04-25 10:30:44 -0400506}
507
Charles Clément6b35b7b2010-05-07 12:30:19 -0700508void
Forest Bond5449c682009-04-25 10:30:44 -0400509VNTWIFIvGetTxRate(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700510 void *pMgmtHandle,
511 unsigned char *pbyDestAddress,
512 unsigned short *pwTxDataRate,
513 unsigned char *pbyACKRate,
514 unsigned char *pbyCCKBasicRate,
515 unsigned char *pbyOFDMBasicRate
516)
Forest Bond5449c682009-04-25 10:30:44 -0400517{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700518 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
519 unsigned int uNodeIndex = 0;
520 unsigned short wTxDataRate = RATE_1M;
521 unsigned char byACKRate = RATE_1M;
522 unsigned char byCCKBasicRate = RATE_1M;
523 unsigned char byOFDMBasicRate = RATE_24M;
524 PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
525 PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400526
Joe Perchesd9d644e2013-03-18 10:45:08 -0700527 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
528 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
Merlin Chlosta5c3ddb32014-06-19 19:59:32 +0200529 /* Adhoc Tx rate decided from node DB */
Joe Perchesd9d644e2013-03-18 10:45:08 -0700530 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
531 wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
532 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
533 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
534 } else {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300535 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700536 wTxDataRate = RATE_2M;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300537 else
Joe Perchesd9d644e2013-03-18 10:45:08 -0700538 wTxDataRate = RATE_24M;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300539
Joe Perchesd9d644e2013-03-18 10:45:08 -0700540 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
541 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
542 }
Merlin Chlosta5c3ddb32014-06-19 19:59:32 +0200543 } else { /* Infrastructure: rate decided from AP Node, index = 0 */
Forest Bond5449c682009-04-25 10:30:44 -0400544
545 wTxDataRate = (pMgmt->sNodeDBTable[0].wTxDataRate);
546#ifdef PLICE_DEBUG
Guillaume Clement941ead92014-07-25 01:06:21 +0200547 pr_debug("GetTxRate:AP MAC is %pM,TxRate is %d\n",
Joe Perchesd9d644e2013-03-18 10:45:08 -0700548 pMgmt->sNodeDBTable[0].abyMACAddr, wTxDataRate);
Forest Bond5449c682009-04-25 10:30:44 -0400549#endif
550
Joe Perchesd9d644e2013-03-18 10:45:08 -0700551 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
552 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
553 }
554 byACKRate = VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate,
555 pSupportRateIEs,
556 pExtSupportRateIEs
557);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300558 if (byACKRate > (unsigned char) wTxDataRate)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700559 byACKRate = (unsigned char) wTxDataRate;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300560
Joe Perchesd9d644e2013-03-18 10:45:08 -0700561 byCCKBasicRate = VNTWIFIbyGetACKTxRate(RATE_11M,
562 pSupportRateIEs,
563 pExtSupportRateIEs
564);
565 byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
566 pSupportRateIEs,
567 pExtSupportRateIEs
568);
569 *pwTxDataRate = wTxDataRate;
570 *pbyACKRate = byACKRate;
571 *pbyCCKBasicRate = byCCKBasicRate;
572 *pbyOFDMBasicRate = byOFDMBasicRate;
Forest Bond5449c682009-04-25 10:30:44 -0400573}
574
Charles Clément3fc9b582010-06-24 11:02:27 -0700575unsigned char
Forest Bond5449c682009-04-25 10:30:44 -0400576VNTWIFIbyGetKeyCypher(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700577 void *pMgmtHandle,
578 bool bGroupKey
579)
Forest Bond5449c682009-04-25 10:30:44 -0400580{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700581 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400582
Guido Martínezbc5cf652014-04-19 16:45:00 -0300583 if (bGroupKey)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700584 return pMgmt->byCSSGK;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300585 else
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700586 return pMgmt->byCSSPK;
Forest Bond5449c682009-04-25 10:30:44 -0400587}
588
Charles Clément7b6a0012010-08-01 17:15:50 +0200589bool
Joe Perchesd9d644e2013-03-18 10:45:08 -0700590VNTWIFIbSetPMKIDCache(
591 void *pMgmtObject,
592 unsigned long ulCount,
593 void *pPMKIDInfo
594)
Forest Bond5449c682009-04-25 10:30:44 -0400595{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700596 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400597
Guido Martínezbc5cf652014-04-19 16:45:00 -0300598 if (ulCount > MAX_PMKID_CACHE)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700599 return false;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300600
Joe Perchesd9d644e2013-03-18 10:45:08 -0700601 pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
602 memcpy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700603 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400604}
605
Charles Clément2986db52010-06-24 11:02:26 -0700606unsigned short
Forest Bond5449c682009-04-25 10:30:44 -0400607VNTWIFIwGetMaxSupportRate(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700608 void *pMgmtObject
609)
Forest Bond5449c682009-04-25 10:30:44 -0400610{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700611 unsigned short wRate = RATE_54M;
612 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400613
Joe Perchesd9d644e2013-03-18 10:45:08 -0700614 for (wRate = RATE_54M; wRate > RATE_1M; wRate--) {
Guido Martínezbc5cf652014-04-19 16:45:00 -0300615 if (pMgmt->sNodeDBTable[0].wSuppRate & (1<<wRate))
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700616 return wRate;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700617 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300618
619 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700620 return RATE_6M;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300621 else
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700622 return RATE_1M;
Forest Bond5449c682009-04-25 10:30:44 -0400623}
624
Charles Clément6b35b7b2010-05-07 12:30:19 -0700625void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700626VNTWIFIvSet11h(
627 void *pMgmtObject,
628 bool b11hEnable
629)
Forest Bond5449c682009-04-25 10:30:44 -0400630{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700631 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400632
Joe Perchesd9d644e2013-03-18 10:45:08 -0700633 pMgmt->b11hEnable = b11hEnable;
Forest Bond5449c682009-04-25 10:30:44 -0400634}
635
Charles Clément7b6a0012010-08-01 17:15:50 +0200636bool
Forest Bond5449c682009-04-25 10:30:44 -0400637VNTWIFIbMeasureReport(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700638 void *pMgmtObject,
639 bool bEndOfReport,
640 void *pvMeasureEID,
641 unsigned char byReportMode,
642 unsigned char byBasicMap,
643 unsigned char byCCAFraction,
644 unsigned char *pbyRPIs
645)
Forest Bond5449c682009-04-25 10:30:44 -0400646{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700647 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
648 unsigned char *pbyCurrentEID = (unsigned char *)(pMgmt->pCurrMeasureEIDRep);
Forest Bond5449c682009-04-25 10:30:44 -0400649
Joe Perchesd9d644e2013-03-18 10:45:08 -0700650 if ((pvMeasureEID != NULL) &&
651 (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
652) {
653 pMgmt->pCurrMeasureEIDRep->byElementID = WLAN_EID_MEASURE_REP;
654 pMgmt->pCurrMeasureEIDRep->len = 3;
655 pMgmt->pCurrMeasureEIDRep->byToken = ((PWLAN_IE_MEASURE_REQ)pvMeasureEID)->byToken;
656 pMgmt->pCurrMeasureEIDRep->byMode = byReportMode;
657 pMgmt->pCurrMeasureEIDRep->byType = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byType;
658 switch (pMgmt->pCurrMeasureEIDRep->byType) {
659 case MEASURE_TYPE_BASIC:
660 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_BASIC);
661 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sBasic),
662 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
663 sizeof(MEASEURE_REQ));
664 pMgmt->pCurrMeasureEIDRep->sRep.sBasic.byMap = byBasicMap;
665 break;
666 case MEASURE_TYPE_CCA:
667 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_CCA);
668 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sCCA),
669 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
670 sizeof(MEASEURE_REQ));
671 pMgmt->pCurrMeasureEIDRep->sRep.sCCA.byCCABusyFraction = byCCAFraction;
672 break;
673 case MEASURE_TYPE_RPI:
674 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_RPI);
675 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sRPI),
676 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
677 sizeof(MEASEURE_REQ));
678 memcpy(pMgmt->pCurrMeasureEIDRep->sRep.sRPI.abyRPIdensity, pbyRPIs, 8);
679 break;
680 default:
681 break;
682 }
683 pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
684 pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
685 pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
686 }
Guillaume Clementcba60902014-07-25 01:06:25 +0200687 if (bEndOfReport)
Joe Perchesd9d644e2013-03-18 10:45:08 -0700688 IEEE11hbMSRRepTx(pMgmt);
Guido Martínez4e8a7e52014-04-19 16:44:59 -0300689
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700690 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400691}
692
Charles Clément7b6a0012010-08-01 17:15:50 +0200693bool
Forest Bond5449c682009-04-25 10:30:44 -0400694VNTWIFIbChannelSwitch(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700695 void *pMgmtObject,
696 unsigned char byNewChannel
697)
Forest Bond5449c682009-04-25 10:30:44 -0400698{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700699 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400700
Joe Perchesd9d644e2013-03-18 10:45:08 -0700701 pMgmt->uCurrChannel = byNewChannel;
702 pMgmt->bSwitchChannel = false;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700703 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400704}