Btrfs: device_list_add() should not update list when mounted
[linux/fpc-iii.git] / drivers / staging / vt6655 / vntwifi.c
blob7d61598563c75609b2cbd6277a713bfd77147ac5
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
20 * File: vntwifi.c
22 * Purpose: export functions for vntwifi lib
24 * Functions:
26 * Revision History:
28 * Author: Yiching Chen
30 * Date: feb. 2, 2005
34 #include "vntwifi.h"
35 #include "IEEE11h.h"
36 #include "country.h"
37 #include "device.h"
38 #include "wmgr.h"
39 #include "datarate.h"
41 /*--------------------- Static Definitions -------------------------*/
43 /*--------------------- Static Classes ----------------------------*/
45 /*--------------------- Static Variables --------------------------*/
47 /*--------------------- Static Functions --------------------------*/
49 /*--------------------- Export Variables --------------------------*/
51 /*--------------------- Export Functions --------------------------*/
53 /*+
55 * Description:
56 * Set Operation Mode
58 * Parameters:
59 * In:
60 * pMgmtHandle - pointer to management object
61 * eOPMode - Operation Mode
62 * Out:
63 * none
65 * Return Value: none
67 -*/
68 void
69 VNTWIFIvSetOPMode(
70 void *pMgmtHandle,
71 WMAC_CONFIG_MODE eOPMode
74 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
76 pMgmt->eConfigMode = eOPMode;
79 /*+
81 * Description:
82 * Set Operation Mode
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
93 * Return Value: none
95 -*/
96 void
97 VNTWIFIvSetIBSSParameter(
98 void *pMgmtHandle,
99 unsigned short wBeaconPeriod,
100 unsigned short wATIMWindow,
101 unsigned int uChannel
104 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
106 pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
107 pMgmt->wIBSSATIMWindow = wATIMWindow;
108 pMgmt->uIBSSChannel = uChannel;
113 * Description:
114 * Get current SSID
116 * Parameters:
117 * In:
118 * pMgmtHandle - pointer to management object
119 * Out:
120 * none
122 * Return Value: current SSID pointer.
125 PWLAN_IE_SSID
126 VNTWIFIpGetCurrentSSID(
127 void *pMgmtHandle
130 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
131 return (PWLAN_IE_SSID) pMgmt->abyCurrSSID;
136 * Description:
137 * Get current link channel
139 * Parameters:
140 * In:
141 * pMgmtHandle - pointer to management object
142 * Out:
143 * none
145 * Return Value: current Channel.
148 unsigned int
149 VNTWIFIpGetCurrentChannel(
150 void *pMgmtHandle
153 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
154 if (pMgmtHandle != NULL)
155 return pMgmt->uCurrChannel;
157 return 0;
162 * Description:
163 * Get current Assoc ID
165 * Parameters:
166 * In:
167 * pMgmtHandle - pointer to management object
168 * Out:
169 * none
171 * Return Value: current Assoc ID
174 unsigned short
175 VNTWIFIwGetAssocID(
176 void *pMgmtHandle
179 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
180 return pMgmt->wCurrAID;
185 * Description:
186 * This routine return max support rate of IES
188 * Parameters:
189 * In:
190 * pSupportRateIEs
191 * pExtSupportRateIEs
193 * Out:
195 * Return Value: max support rate
198 unsigned char
199 VNTWIFIbyGetMaxSupportRate(
200 PWLAN_IE_SUPP_RATES pSupportRateIEs,
201 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
204 unsigned char byMaxSupportRate = RATE_1M;
205 unsigned char bySupportRate = RATE_1M;
206 unsigned int ii = 0;
208 if (pSupportRateIEs) {
209 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
210 bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
211 if (bySupportRate > byMaxSupportRate)
212 byMaxSupportRate = bySupportRate;
216 if (pExtSupportRateIEs) {
217 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
218 bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
219 if (bySupportRate > byMaxSupportRate)
220 byMaxSupportRate = bySupportRate;
225 return byMaxSupportRate;
230 * Description:
231 * This routine return data rate of ACK packtet
233 * Parameters:
234 * In:
235 * byRxDataRate
236 * pSupportRateIEs
237 * pExtSupportRateIEs
239 * Out:
241 * Return Value: max support rate
244 unsigned char
245 VNTWIFIbyGetACKTxRate(
246 unsigned char byRxDataRate,
247 PWLAN_IE_SUPP_RATES pSupportRateIEs,
248 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
251 unsigned char byMaxAckRate;
252 unsigned char byBasicRate;
253 unsigned int ii;
255 if (byRxDataRate <= RATE_11M) {
256 byMaxAckRate = RATE_1M;
257 } else {
258 // 24M is mandatory for 802.11a and 802.11g
259 byMaxAckRate = RATE_24M;
261 if (pSupportRateIEs) {
262 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
263 if (pSupportRateIEs->abyRates[ii] & 0x80) {
264 byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
265 if ((byBasicRate <= byRxDataRate) &&
266 (byBasicRate > byMaxAckRate)) {
267 byMaxAckRate = byBasicRate;
272 if (pExtSupportRateIEs) {
273 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
274 if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
275 byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
276 if ((byBasicRate <= byRxDataRate) &&
277 (byBasicRate > byMaxAckRate)) {
278 byMaxAckRate = byBasicRate;
284 return byMaxAckRate;
289 * Description:
290 * Set Authentication Mode
292 * Parameters:
293 * In:
294 * pMgmtHandle - pointer to management object
295 * eAuthMode - Authentication mode
296 * Out:
297 * none
299 * Return Value: none
302 void
303 VNTWIFIvSetAuthenticationMode(
304 void *pMgmtHandle,
305 WMAC_AUTHENTICATION_MODE eAuthMode
308 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
310 pMgmt->eAuthenMode = eAuthMode;
311 if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
312 (eAuthMode == WMAC_AUTH_AUTO)) {
313 pMgmt->bShareKeyAlgorithm = true;
314 } else {
315 pMgmt->bShareKeyAlgorithm = false;
321 * Description:
322 * Set Encryption Mode
324 * Parameters:
325 * In:
326 * pMgmtHandle - pointer to management object
327 * eAuthMode - Authentication mode
328 * Out:
329 * none
331 * Return Value: none
334 void
335 VNTWIFIvSetEncryptionMode(
336 void *pMgmtHandle,
337 WMAC_ENCRYPTION_MODE eEncryptionMode
340 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
342 pMgmt->eEncryptionMode = eEncryptionMode;
343 if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
344 (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
345 (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled)) {
346 pMgmt->bPrivacyInvoked = true;
347 } else {
348 pMgmt->bPrivacyInvoked = false;
352 bool
353 VNTWIFIbConfigPhyMode(
354 void *pMgmtHandle,
355 CARD_PHY_TYPE ePhyType
358 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
360 if ((ePhyType != PHY_TYPE_AUTO) &&
361 (ePhyType != pMgmt->eCurrentPHYMode)) {
362 if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL) == true)
363 pMgmt->eCurrentPHYMode = ePhyType;
364 else
365 return false;
367 pMgmt->eConfigPHYMode = ePhyType;
368 return true;
371 void
372 VNTWIFIbGetConfigPhyMode(
373 void *pMgmtHandle,
374 void *pePhyType
377 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
379 if ((pMgmt != NULL) && (pePhyType != NULL))
380 *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
385 * Description:
386 * Clear BSS List Database except current assoc BSS
388 * Parameters:
389 * In:
390 * pMgmtHandle - Management Object structure
391 * bLinkPass - Current Link status
392 * Out:
394 * Return Value: None.
400 * Description:
401 * Query BSS List in management database
403 * Parameters:
404 * In:
405 * pMgmtHandle - Management Object structure
406 * Out:
407 * puBSSCount - BSS count
408 * pvFirstBSS - pointer to first BSS
410 * Return Value: None.
414 void
415 VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount, void **pvFirstBSS)
417 unsigned int ii = 0;
418 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
419 PKnownBSS pBSS = NULL;
420 unsigned int uCount = 0;
422 *pvFirstBSS = NULL;
424 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
425 pBSS = &(pMgmt->sBSSList[ii]);
426 if (!pBSS->bActive)
427 continue;
429 if (*pvFirstBSS == NULL)
430 *pvFirstBSS = &(pMgmt->sBSSList[ii]);
432 uCount++;
434 *puBSSCount = uCount;
437 void
438 VNTWIFIvGetNextBSS(
439 void *pMgmtHandle,
440 void *pvCurrentBSS,
441 void **pvNextBSS
444 PKnownBSS pBSS = (PKnownBSS) pvCurrentBSS;
445 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
447 *pvNextBSS = NULL;
449 while (*pvNextBSS == NULL) {
450 pBSS++;
451 if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM]))
452 return;
454 if (pBSS->bActive == true) {
455 *pvNextBSS = pBSS;
456 return;
463 * Description:
464 * Update Tx attemps, Tx failure counter in Node DB
466 * In:
467 * Out:
468 * none
470 * Return Value: none
473 void
474 VNTWIFIvUpdateNodeTxCounter(
475 void *pMgmtHandle,
476 unsigned char *pbyDestAddress,
477 bool bTxOk,
478 unsigned short wRate,
479 unsigned char *pbyTxFailCount
482 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
483 unsigned int uNodeIndex = 0;
484 unsigned int ii;
486 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
487 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
488 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == false)
489 return;
492 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
493 if (bTxOk) {
494 // transmit success, TxAttempts at least plus one
495 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
496 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
497 } else {
498 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
500 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
501 for (ii = 0; ii < MAX_RATE; ii++)
502 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
504 return;
507 void
508 VNTWIFIvGetTxRate(
509 void *pMgmtHandle,
510 unsigned char *pbyDestAddress,
511 unsigned short *pwTxDataRate,
512 unsigned char *pbyACKRate,
513 unsigned char *pbyCCKBasicRate,
514 unsigned char *pbyOFDMBasicRate
517 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
518 unsigned int uNodeIndex = 0;
519 unsigned short wTxDataRate = RATE_1M;
520 unsigned char byACKRate = RATE_1M;
521 unsigned char byCCKBasicRate = RATE_1M;
522 unsigned char byOFDMBasicRate = RATE_24M;
523 PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
524 PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
526 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
527 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
528 // Adhoc Tx rate decided from node DB
529 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
530 wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
531 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
532 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
533 } else {
534 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A)
535 wTxDataRate = RATE_2M;
536 else
537 wTxDataRate = RATE_24M;
539 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
540 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
542 } else { // Infrastructure: rate decided from AP Node, index = 0
544 wTxDataRate = (pMgmt->sNodeDBTable[0].wTxDataRate);
545 #ifdef PLICE_DEBUG
546 printk(KERN_DEBUG "GetTxRate:AP MAC is %pM,TxRate is %d\n",
547 pMgmt->sNodeDBTable[0].abyMACAddr, wTxDataRate);
548 #endif
550 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
551 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
553 byACKRate = VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate,
554 pSupportRateIEs,
555 pExtSupportRateIEs
557 if (byACKRate > (unsigned char) wTxDataRate)
558 byACKRate = (unsigned char) wTxDataRate;
560 byCCKBasicRate = VNTWIFIbyGetACKTxRate(RATE_11M,
561 pSupportRateIEs,
562 pExtSupportRateIEs
564 byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
565 pSupportRateIEs,
566 pExtSupportRateIEs
568 *pwTxDataRate = wTxDataRate;
569 *pbyACKRate = byACKRate;
570 *pbyCCKBasicRate = byCCKBasicRate;
571 *pbyOFDMBasicRate = byOFDMBasicRate;
572 return;
575 unsigned char
576 VNTWIFIbyGetKeyCypher(
577 void *pMgmtHandle,
578 bool bGroupKey
581 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
583 if (bGroupKey)
584 return pMgmt->byCSSGK;
585 else
586 return pMgmt->byCSSPK;
589 bool
590 VNTWIFIbSetPMKIDCache(
591 void *pMgmtObject,
592 unsigned long ulCount,
593 void *pPMKIDInfo
596 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
598 if (ulCount > MAX_PMKID_CACHE)
599 return false;
601 pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
602 memcpy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
603 return true;
606 unsigned short
607 VNTWIFIwGetMaxSupportRate(
608 void *pMgmtObject
611 unsigned short wRate = RATE_54M;
612 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
614 for (wRate = RATE_54M; wRate > RATE_1M; wRate--) {
615 if (pMgmt->sNodeDBTable[0].wSuppRate & (1<<wRate))
616 return wRate;
619 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)
620 return RATE_6M;
621 else
622 return RATE_1M;
625 void
626 VNTWIFIvSet11h(
627 void *pMgmtObject,
628 bool b11hEnable
631 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
633 pMgmt->b11hEnable = b11hEnable;
636 bool
637 VNTWIFIbMeasureReport(
638 void *pMgmtObject,
639 bool bEndOfReport,
640 void *pvMeasureEID,
641 unsigned char byReportMode,
642 unsigned char byBasicMap,
643 unsigned char byCCAFraction,
644 unsigned char *pbyRPIs
647 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
648 unsigned char *pbyCurrentEID = (unsigned char *)(pMgmt->pCurrMeasureEIDRep);
650 if ((pvMeasureEID != NULL) &&
651 (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
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;
683 pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
684 pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
685 pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
687 if (bEndOfReport) {
688 IEEE11hbMSRRepTx(pMgmt);
691 return true;
694 bool
695 VNTWIFIbChannelSwitch(
696 void *pMgmtObject,
697 unsigned char byNewChannel
700 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
702 pMgmt->uCurrChannel = byNewChannel;
703 pMgmt->bSwitchChannel = false;
704 return true;