blob: d8f4f8e7d05eba72281375483ca35fe09f7fbd46 [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 -------------------------*/
42//static int msglevel =MSG_LEVEL_DEBUG;
43//static int msglevel =MSG_LEVEL_INFO;
44
45/*--------------------- Static Classes ----------------------------*/
46
47/*--------------------- Static Variables --------------------------*/
48
49/*--------------------- Static Functions --------------------------*/
50
51/*--------------------- Export Variables --------------------------*/
52
53/*--------------------- Export Functions --------------------------*/
54
55/*+
56 *
57 * Description:
58 * Set Operation Mode
59 *
60 * Parameters:
61 * In:
62 * pMgmtHandle - pointer to management object
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070063 * eOPMode - Operation Mode
Forest Bond5449c682009-04-25 10:30:44 -040064 * Out:
65 * none
66 *
67 * Return Value: none
68 *
Joe Perchesd9d644e2013-03-18 10:45:08 -070069 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -070070void
Joe Perchesd9d644e2013-03-18 10:45:08 -070071VNTWIFIvSetOPMode(
72 void *pMgmtHandle,
73 WMAC_CONFIG_MODE eOPMode
74)
Forest Bond5449c682009-04-25 10:30:44 -040075{
Joe Perchesd9d644e2013-03-18 10:45:08 -070076 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -040077
Joe Perchesd9d644e2013-03-18 10:45:08 -070078 pMgmt->eConfigMode = eOPMode;
Forest Bond5449c682009-04-25 10:30:44 -040079}
80
Forest Bond5449c682009-04-25 10:30:44 -040081/*+
82 *
83 * Description:
84 * Set Operation Mode
85 *
86 * Parameters:
87 * In:
88 * pMgmtHandle - pointer to management object
89 * wBeaconPeriod - Beacon Period
90 * wATIMWindow - ATIM window
91 * uChannel - channel number
92 * Out:
93 * none
94 *
95 * Return Value: none
96 *
Joe Perchesd9d644e2013-03-18 10:45:08 -070097 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -070098void
Joe Perchesd9d644e2013-03-18 10:45:08 -070099VNTWIFIvSetIBSSParameter(
100 void *pMgmtHandle,
101 unsigned short wBeaconPeriod,
102 unsigned short wATIMWindow,
103 unsigned int uChannel
104)
Forest Bond5449c682009-04-25 10:30:44 -0400105{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700106 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400107
Joe Perchesd9d644e2013-03-18 10:45:08 -0700108 pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
109 pMgmt->wIBSSATIMWindow = wATIMWindow;
110 pMgmt->uIBSSChannel = uChannel;
Forest Bond5449c682009-04-25 10:30:44 -0400111}
112
113/*+
114 *
115 * Description:
116 * Get current SSID
117 *
118 * Parameters:
119 * In:
120 * pMgmtHandle - pointer to management object
121 * Out:
122 * none
123 *
124 * Return Value: current SSID pointer.
125 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700126 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400127PWLAN_IE_SSID
Joe Perchesd9d644e2013-03-18 10:45:08 -0700128VNTWIFIpGetCurrentSSID(
129 void *pMgmtHandle
130)
Forest Bond5449c682009-04-25 10:30:44 -0400131{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700132 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700133 return (PWLAN_IE_SSID) pMgmt->abyCurrSSID;
Forest Bond5449c682009-04-25 10:30:44 -0400134}
135
136/*+
137 *
138 * Description:
139 * Get current link channel
140 *
141 * Parameters:
142 * In:
143 * pMgmtHandle - pointer to management object
144 * Out:
145 * none
146 *
147 * Return Value: current Channel.
148 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700149 -*/
Charles Clémentb6e95cd2010-06-02 09:52:01 -0700150unsigned int
Joe Perchesd9d644e2013-03-18 10:45:08 -0700151VNTWIFIpGetCurrentChannel(
152 void *pMgmtHandle
153)
Forest Bond5449c682009-04-25 10:30:44 -0400154{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700155 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
156 if (pMgmtHandle != NULL) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700157 return pMgmt->uCurrChannel;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700158 }
159 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;
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700182 return pMgmt->wCurrAID;
Forest Bond5449c682009-04-25 10:30:44 -0400183}
184
Forest Bond5449c682009-04-25 10:30:44 -0400185/*+
186 *
187 * Description:
188 * This routine return max support rate of IES
189 *
190 * Parameters:
191 * In:
192 * pSupportRateIEs
193 * pExtSupportRateIEs
194 *
195 * Out:
196 *
197 * Return Value: max support rate
198 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700199 -*/
Charles Clément3fc9b582010-06-24 11:02:27 -0700200unsigned char
Joe Perchesd9d644e2013-03-18 10:45:08 -0700201VNTWIFIbyGetMaxSupportRate(
202 PWLAN_IE_SUPP_RATES pSupportRateIEs,
203 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
204)
Forest Bond5449c682009-04-25 10:30:44 -0400205{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700206 unsigned char byMaxSupportRate = RATE_1M;
207 unsigned char bySupportRate = RATE_1M;
208 unsigned int ii = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400209
Joe Perchesd9d644e2013-03-18 10:45:08 -0700210 if (pSupportRateIEs) {
211 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
212 bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
213 if (bySupportRate > byMaxSupportRate) {
214 byMaxSupportRate = bySupportRate;
215 }
216 }
217 }
218 if (pExtSupportRateIEs) {
219 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
220 bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
221 if (bySupportRate > byMaxSupportRate) {
222 byMaxSupportRate = bySupportRate;
223 }
224 }
225 }
Forest Bond5449c682009-04-25 10:30:44 -0400226
Joe Perchesd9d644e2013-03-18 10:45:08 -0700227 return byMaxSupportRate;
Forest Bond5449c682009-04-25 10:30:44 -0400228}
229
230/*+
231 *
232 * Description:
233 * This routine return data rate of ACK packtet
234 *
235 * Parameters:
236 * In:
237 * byRxDataRate
238 * pSupportRateIEs
239 * pExtSupportRateIEs
240 *
241 * Out:
242 *
243 * Return Value: max support rate
244 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700245 -*/
Charles Clément3fc9b582010-06-24 11:02:27 -0700246unsigned char
Joe Perchesd9d644e2013-03-18 10:45:08 -0700247VNTWIFIbyGetACKTxRate(
248 unsigned char byRxDataRate,
249 PWLAN_IE_SUPP_RATES pSupportRateIEs,
250 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
251)
Forest Bond5449c682009-04-25 10:30:44 -0400252{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700253 unsigned char byMaxAckRate;
254 unsigned char byBasicRate;
255 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400256
Joe Perchesd9d644e2013-03-18 10:45:08 -0700257 if (byRxDataRate <= RATE_11M) {
258 byMaxAckRate = RATE_1M;
259 } else {
260 // 24M is mandatory for 802.11a and 802.11g
261 byMaxAckRate = RATE_24M;
262 }
263 if (pSupportRateIEs) {
264 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
265 if (pSupportRateIEs->abyRates[ii] & 0x80) {
266 byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
267 if ((byBasicRate <= byRxDataRate) &&
268 (byBasicRate > byMaxAckRate)) {
269 byMaxAckRate = byBasicRate;
270 }
271 }
272 }
273 }
274 if (pExtSupportRateIEs) {
275 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
276 if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
277 byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
278 if ((byBasicRate <= byRxDataRate) &&
279 (byBasicRate > byMaxAckRate)) {
280 byMaxAckRate = byBasicRate;
281 }
282 }
283 }
284 }
Forest Bond5449c682009-04-25 10:30:44 -0400285
Joe Perchesd9d644e2013-03-18 10:45:08 -0700286 return byMaxAckRate;
Forest Bond5449c682009-04-25 10:30:44 -0400287}
288
289/*+
290 *
291 * Description:
292 * Set Authentication Mode
293 *
294 * Parameters:
295 * In:
296 * pMgmtHandle - pointer to management object
297 * eAuthMode - Authentication mode
298 * Out:
299 * none
300 *
301 * Return Value: none
302 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700303 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700304void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700305VNTWIFIvSetAuthenticationMode(
306 void *pMgmtHandle,
307 WMAC_AUTHENTICATION_MODE eAuthMode
308)
Forest Bond5449c682009-04-25 10:30:44 -0400309{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700310 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400311
Joe Perchesd9d644e2013-03-18 10:45:08 -0700312 pMgmt->eAuthenMode = eAuthMode;
313 if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
314 (eAuthMode == WMAC_AUTH_AUTO)) {
315 pMgmt->bShareKeyAlgorithm = true;
316 } else {
317 pMgmt->bShareKeyAlgorithm = false;
318 }
Forest Bond5449c682009-04-25 10:30:44 -0400319}
320
321/*+
322 *
323 * Description:
324 * Set Encryption Mode
325 *
326 * Parameters:
327 * In:
328 * pMgmtHandle - pointer to management object
329 * eAuthMode - Authentication mode
330 * Out:
331 * none
332 *
333 * Return Value: none
334 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700335 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700336void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700337VNTWIFIvSetEncryptionMode(
338 void *pMgmtHandle,
339 WMAC_ENCRYPTION_MODE eEncryptionMode
340)
Forest Bond5449c682009-04-25 10:30:44 -0400341{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700342 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400343
Joe Perchesd9d644e2013-03-18 10:45:08 -0700344 pMgmt->eEncryptionMode = eEncryptionMode;
345 if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
346 (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
347 (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled)) {
348 pMgmt->bPrivacyInvoked = true;
349 } else {
350 pMgmt->bPrivacyInvoked = false;
351 }
Forest Bond5449c682009-04-25 10:30:44 -0400352}
353
Charles Clément7b6a0012010-08-01 17:15:50 +0200354bool
Joe Perchesd9d644e2013-03-18 10:45:08 -0700355VNTWIFIbConfigPhyMode(
356 void *pMgmtHandle,
357 CARD_PHY_TYPE ePhyType
358)
Forest Bond5449c682009-04-25 10:30:44 -0400359{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700360 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400361
Joe Perchesd9d644e2013-03-18 10:45:08 -0700362 if ((ePhyType != PHY_TYPE_AUTO) &&
363 (ePhyType != pMgmt->eCurrentPHYMode)) {
364 if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL) == true) {
365 pMgmt->eCurrentPHYMode = ePhyType;
366 } else {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700367 return false;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700368 }
369 }
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
Joe Perchesd9d644e2013-03-18 10:45:08 -0700382 if ((pMgmt != NULL) && (pePhyType != NULL)) {
383 *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
384 }
Forest Bond5449c682009-04-25 10:30:44 -0400385}
386
387/*+
388 *
389 * Description:
390 * Clear BSS List Database except current assoc BSS
391 *
392 * Parameters:
393 * In:
394 * pMgmtHandle - Management Object structure
395 * bLinkPass - Current Link status
396 * Out:
397 *
398 * Return Value: None.
399 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700400 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400401
Forest Bond5449c682009-04-25 10:30:44 -0400402/*+
403 *
404 * Description:
405 * Query BSS List in management database
406 *
407 * Parameters:
408 * In:
409 * pMgmtHandle - Management Object structure
410 * Out:
411 * puBSSCount - BSS count
412 * pvFirstBSS - pointer to first BSS
413 *
414 * Return Value: None.
415 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700416 -*/
Forest Bond5449c682009-04-25 10:30:44 -0400417
Charles Clément6b35b7b2010-05-07 12:30:19 -0700418void
Charles Clémentfe4f34b2010-06-25 10:48:53 -0700419VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount, void **pvFirstBSS)
Forest Bond5449c682009-04-25 10:30:44 -0400420{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700421 unsigned int ii = 0;
422 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
423 PKnownBSS pBSS = NULL;
424 unsigned int uCount = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400425
Joe Perchesd9d644e2013-03-18 10:45:08 -0700426 *pvFirstBSS = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400427
Joe Perchesd9d644e2013-03-18 10:45:08 -0700428 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
429 pBSS = &(pMgmt->sBSSList[ii]);
430 if (!pBSS->bActive) {
431 continue;
432 }
433 if (*pvFirstBSS == NULL) {
434 *pvFirstBSS = &(pMgmt->sBSSList[ii]);
435 }
436 uCount++;
437 }
438 *puBSSCount = uCount;
Forest Bond5449c682009-04-25 10:30:44 -0400439}
440
Charles Clément6b35b7b2010-05-07 12:30:19 -0700441void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700442VNTWIFIvGetNextBSS(
443 void *pMgmtHandle,
444 void *pvCurrentBSS,
445 void **pvNextBSS
446)
Forest Bond5449c682009-04-25 10:30:44 -0400447{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700448 PKnownBSS pBSS = (PKnownBSS) pvCurrentBSS;
449 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400450
Joe Perchesd9d644e2013-03-18 10:45:08 -0700451 *pvNextBSS = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400452
Joe Perchesd9d644e2013-03-18 10:45:08 -0700453 while (*pvNextBSS == NULL) {
454 pBSS++;
455 if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM])) {
456 return;
457 }
458 if (pBSS->bActive == true) {
459 *pvNextBSS = pBSS;
460 return;
461 }
462 }
Forest Bond5449c682009-04-25 10:30:44 -0400463}
464
Forest Bond5449c682009-04-25 10:30:44 -0400465/*+
466 *
467 * Description:
468 * Update Tx attemps, Tx failure counter in Node DB
469 *
470 * In:
471 * Out:
472 * none
473 *
474 * Return Value: none
475 *
Joe Perchesd9d644e2013-03-18 10:45:08 -0700476 -*/
Charles Clément6b35b7b2010-05-07 12:30:19 -0700477void
Forest Bond5449c682009-04-25 10:30:44 -0400478VNTWIFIvUpdateNodeTxCounter(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700479 void *pMgmtHandle,
480 unsigned char *pbyDestAddress,
481 bool bTxOk,
482 unsigned short wRate,
483 unsigned char *pbyTxFailCount
484)
Forest Bond5449c682009-04-25 10:30:44 -0400485{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700486 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
487 unsigned int uNodeIndex = 0;
488 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400489
Joe Perchesd9d644e2013-03-18 10:45:08 -0700490 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
491 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
492 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == false) {
493 return;
494 }
495 }
496 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
497 if (bTxOk == true) {
498 // transmit success, TxAttempts at least plus one
499 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
500 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
501 } else {
502 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
503 }
504 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
505 for (ii = 0; ii < MAX_RATE; ii++) {
506 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
507 }
508 return;
Forest Bond5449c682009-04-25 10:30:44 -0400509}
510
Charles Clément6b35b7b2010-05-07 12:30:19 -0700511void
Forest Bond5449c682009-04-25 10:30:44 -0400512VNTWIFIvGetTxRate(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700513 void *pMgmtHandle,
514 unsigned char *pbyDestAddress,
515 unsigned short *pwTxDataRate,
516 unsigned char *pbyACKRate,
517 unsigned char *pbyCCKBasicRate,
518 unsigned char *pbyOFDMBasicRate
519)
Forest Bond5449c682009-04-25 10:30:44 -0400520{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700521 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
522 unsigned int uNodeIndex = 0;
523 unsigned short wTxDataRate = RATE_1M;
524 unsigned char byACKRate = RATE_1M;
525 unsigned char byCCKBasicRate = RATE_1M;
526 unsigned char byOFDMBasicRate = RATE_24M;
527 PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
528 PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
Forest Bond5449c682009-04-25 10:30:44 -0400529
Joe Perchesd9d644e2013-03-18 10:45:08 -0700530 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
531 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
532 // Adhoc Tx rate decided from node DB
533 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
534 wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
535 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
536 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
537 } else {
538 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
539 wTxDataRate = RATE_2M;
540 } else {
541 wTxDataRate = RATE_24M;
542 }
543 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
544 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
545 }
546 } else { // Infrastructure: rate decided from AP Node, index = 0
Forest Bond5449c682009-04-25 10:30:44 -0400547
548 wTxDataRate = (pMgmt->sNodeDBTable[0].wTxDataRate);
549#ifdef PLICE_DEBUG
Andy Shevchenko3c02dc22010-09-11 17:17:12 +0300550 printk(KERN_DEBUG "GetTxRate:AP MAC is %pM,TxRate is %d\n",
Joe Perchesd9d644e2013-03-18 10:45:08 -0700551 pMgmt->sNodeDBTable[0].abyMACAddr, wTxDataRate);
Forest Bond5449c682009-04-25 10:30:44 -0400552#endif
553
Joe Perchesd9d644e2013-03-18 10:45:08 -0700554 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
555 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
556 }
557 byACKRate = VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate,
558 pSupportRateIEs,
559 pExtSupportRateIEs
560);
561 if (byACKRate > (unsigned char) wTxDataRate) {
562 byACKRate = (unsigned char) wTxDataRate;
563 }
564 byCCKBasicRate = VNTWIFIbyGetACKTxRate(RATE_11M,
565 pSupportRateIEs,
566 pExtSupportRateIEs
567);
568 byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
569 pSupportRateIEs,
570 pExtSupportRateIEs
571);
572 *pwTxDataRate = wTxDataRate;
573 *pbyACKRate = byACKRate;
574 *pbyCCKBasicRate = byCCKBasicRate;
575 *pbyOFDMBasicRate = byOFDMBasicRate;
576 return;
Forest Bond5449c682009-04-25 10:30:44 -0400577}
578
Charles Clément3fc9b582010-06-24 11:02:27 -0700579unsigned char
Forest Bond5449c682009-04-25 10:30:44 -0400580VNTWIFIbyGetKeyCypher(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700581 void *pMgmtHandle,
582 bool bGroupKey
583)
Forest Bond5449c682009-04-25 10:30:44 -0400584{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700585 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
Forest Bond5449c682009-04-25 10:30:44 -0400586
Joe Perchesd9d644e2013-03-18 10:45:08 -0700587 if (bGroupKey == true) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700588 return pMgmt->byCSSGK;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700589 } else {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700590 return pMgmt->byCSSPK;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700591 }
Forest Bond5449c682009-04-25 10:30:44 -0400592}
593
Forest Bond5449c682009-04-25 10:30:44 -0400594/*
Joe Perchesd9d644e2013-03-18 10:45:08 -0700595 bool
596 VNTWIFIbInit(
597 void *pAdapterHandler,
598 void **pMgmtHandler
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700599) {
Joe Perchesd9d644e2013-03-18 10:45:08 -0700600 PSMgmtObject pMgmt = NULL;
601 unsigned int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400602
Joe Perchesd9d644e2013-03-18 10:45:08 -0700603 pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
604 if (pMgmt == NULL) {
605 *pMgmtHandler = NULL;
606 return false;
607 }
Forest Bond5449c682009-04-25 10:30:44 -0400608
Joe Perchesd9d644e2013-03-18 10:45:08 -0700609 memset(pMgmt, 0, sizeof(SMgmtObject));
610 pMgmt->pAdapter = (void *) pAdapterHandler;
Forest Bond5449c682009-04-25 10:30:44 -0400611
Joe Perchesd9d644e2013-03-18 10:45:08 -0700612 // should initial MAC address abyMACAddr
613 for (ii=0; ii<WLAN_BSSID_LEN; ii++) {
614 pMgmt->abyDesireBSSID[ii] = 0xFF;
615 }
616 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
617 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
618 pMgmt->byCSSPK = KEY_CTL_NONE;
619 pMgmt->byCSSGK = KEY_CTL_NONE;
620 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
Forest Bond5449c682009-04-25 10:30:44 -0400621
Joe Perchesd9d644e2013-03-18 10:45:08 -0700622 pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
623 pMgmt->uCmdDequeueIdx = 0;
624 pMgmt->uCmdEnqueueIdx = 0;
625 pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
626 pMgmt->bCmdStop = false;
627 pMgmt->bCmdRunning = false;
Forest Bond5449c682009-04-25 10:30:44 -0400628
Joe Perchesd9d644e2013-03-18 10:45:08 -0700629 *pMgmtHandler = pMgmt;
630 return true;
631 }
Forest Bond5449c682009-04-25 10:30:44 -0400632*/
633
Charles Clément7b6a0012010-08-01 17:15:50 +0200634bool
Joe Perchesd9d644e2013-03-18 10:45:08 -0700635VNTWIFIbSetPMKIDCache(
636 void *pMgmtObject,
637 unsigned long ulCount,
638 void *pPMKIDInfo
639)
Forest Bond5449c682009-04-25 10:30:44 -0400640{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700641 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400642
Joe Perchesd9d644e2013-03-18 10:45:08 -0700643 if (ulCount > MAX_PMKID_CACHE) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700644 return false;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700645 }
646 pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
647 memcpy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700648 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400649}
650
Charles Clément2986db52010-06-24 11:02:26 -0700651unsigned short
Forest Bond5449c682009-04-25 10:30:44 -0400652VNTWIFIwGetMaxSupportRate(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700653 void *pMgmtObject
654)
Forest Bond5449c682009-04-25 10:30:44 -0400655{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700656 unsigned short wRate = RATE_54M;
657 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400658
Joe Perchesd9d644e2013-03-18 10:45:08 -0700659 for (wRate = RATE_54M; wRate > RATE_1M; wRate--) {
660 if (pMgmt->sNodeDBTable[0].wSuppRate & (1<<wRate)) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700661 return wRate;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700662 }
663 }
664 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A) {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700665 return RATE_6M;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700666 } else {
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700667 return RATE_1M;
Joe Perchesd9d644e2013-03-18 10:45:08 -0700668 }
Forest Bond5449c682009-04-25 10:30:44 -0400669}
670
Charles Clément6b35b7b2010-05-07 12:30:19 -0700671void
Joe Perchesd9d644e2013-03-18 10:45:08 -0700672VNTWIFIvSet11h(
673 void *pMgmtObject,
674 bool b11hEnable
675)
Forest Bond5449c682009-04-25 10:30:44 -0400676{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700677 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400678
Joe Perchesd9d644e2013-03-18 10:45:08 -0700679 pMgmt->b11hEnable = b11hEnable;
Forest Bond5449c682009-04-25 10:30:44 -0400680}
681
Charles Clément7b6a0012010-08-01 17:15:50 +0200682bool
Forest Bond5449c682009-04-25 10:30:44 -0400683VNTWIFIbMeasureReport(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700684 void *pMgmtObject,
685 bool bEndOfReport,
686 void *pvMeasureEID,
687 unsigned char byReportMode,
688 unsigned char byBasicMap,
689 unsigned char byCCAFraction,
690 unsigned char *pbyRPIs
691)
Forest Bond5449c682009-04-25 10:30:44 -0400692{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700693 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
694 unsigned char *pbyCurrentEID = (unsigned char *)(pMgmt->pCurrMeasureEIDRep);
Forest Bond5449c682009-04-25 10:30:44 -0400695
Joe Perchesd9d644e2013-03-18 10:45:08 -0700696 //spin_lock_irq(&pDevice->lock);
697 if ((pvMeasureEID != NULL) &&
698 (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
699) {
700 pMgmt->pCurrMeasureEIDRep->byElementID = WLAN_EID_MEASURE_REP;
701 pMgmt->pCurrMeasureEIDRep->len = 3;
702 pMgmt->pCurrMeasureEIDRep->byToken = ((PWLAN_IE_MEASURE_REQ)pvMeasureEID)->byToken;
703 pMgmt->pCurrMeasureEIDRep->byMode = byReportMode;
704 pMgmt->pCurrMeasureEIDRep->byType = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byType;
705 switch (pMgmt->pCurrMeasureEIDRep->byType) {
706 case MEASURE_TYPE_BASIC:
707 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_BASIC);
708 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sBasic),
709 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
710 sizeof(MEASEURE_REQ));
711 pMgmt->pCurrMeasureEIDRep->sRep.sBasic.byMap = byBasicMap;
712 break;
713 case MEASURE_TYPE_CCA:
714 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_CCA);
715 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sCCA),
716 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
717 sizeof(MEASEURE_REQ));
718 pMgmt->pCurrMeasureEIDRep->sRep.sCCA.byCCABusyFraction = byCCAFraction;
719 break;
720 case MEASURE_TYPE_RPI:
721 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_RPI);
722 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sRPI),
723 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
724 sizeof(MEASEURE_REQ));
725 memcpy(pMgmt->pCurrMeasureEIDRep->sRep.sRPI.abyRPIdensity, pbyRPIs, 8);
726 break;
727 default:
728 break;
729 }
730 pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
731 pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
732 pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
733 }
734 if (bEndOfReport == true) {
735 IEEE11hbMSRRepTx(pMgmt);
736 }
737 //spin_unlock_irq(&pDevice->lock);
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700738 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400739}
740
Charles Clément7b6a0012010-08-01 17:15:50 +0200741bool
Forest Bond5449c682009-04-25 10:30:44 -0400742VNTWIFIbChannelSwitch(
Joe Perchesd9d644e2013-03-18 10:45:08 -0700743 void *pMgmtObject,
744 unsigned char byNewChannel
745)
Forest Bond5449c682009-04-25 10:30:44 -0400746{
Joe Perchesd9d644e2013-03-18 10:45:08 -0700747 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
Forest Bond5449c682009-04-25 10:30:44 -0400748
Joe Perchesd9d644e2013-03-18 10:45:08 -0700749 //spin_lock_irq(&pDevice->lock);
750 pMgmt->uCurrChannel = byNewChannel;
751 pMgmt->bSwitchChannel = false;
752 //spin_unlock_irq(&pDevice->lock);
753 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400754}
755
756/*
Joe Perchesd9d644e2013-03-18 10:45:08 -0700757 bool
758 VNTWIFIbRadarPresent(
759 void *pMgmtObject,
760 unsigned char byChannel
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700761) {
Joe Perchesd9d644e2013-03-18 10:45:08 -0700762 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
763 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
764 (byChannel == (unsigned char) pMgmt->uCurrChannel) &&
765 (pMgmt->bSwitchChannel != true) &&
766 (pMgmt->b11hEnable == true)) {
767 if (!compare_ether_addr(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
768 pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(unsigned char) pMgmt->uCurrChannel);
769 pMgmt->bSwitchChannel = true;
770 }
771 BEACONbSendBeacon(pMgmt);
772 CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);
773 }
774 return true;
775 }
Forest Bond5449c682009-04-25 10:30:44 -0400776*/