2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
28 #include <linux/sched.h>
29 #include "../rt_config.h"
32 ========================================================================
35 Remove WPA Key process
38 pAd Pointer to our adapter
39 pBuf Pointer to the where the key stored
42 NDIS_SUCCESS Add key successfully
48 ========================================================================
50 VOID RTMPSetDesiredRates(IN PRTMP_ADAPTER pAdapter, IN LONG Rates)
52 NDIS_802_11_RATES aryRates;
54 memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
55 switch (pAdapter->CommonCfg.PhyMode) {
56 case PHY_11A: // A only
59 aryRates[0] = 0x0c; // 6M
60 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
64 aryRates[0] = 0x12; // 9M
65 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
69 aryRates[0] = 0x18; // 12M
70 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
74 aryRates[0] = 0x24; // 18M
75 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
79 aryRates[0] = 0x30; // 24M
80 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
84 aryRates[0] = 0x48; // 36M
85 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
89 aryRates[0] = 0x60; // 48M
90 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
94 aryRates[0] = 0x6c; // 54M
95 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
100 aryRates[0] = 0x6c; // 54Mbps
101 aryRates[1] = 0x60; // 48Mbps
102 aryRates[2] = 0x48; // 36Mbps
103 aryRates[3] = 0x30; // 24Mbps
104 aryRates[4] = 0x24; // 18M
105 aryRates[5] = 0x18; // 12M
106 aryRates[6] = 0x12; // 9M
107 aryRates[7] = 0x0c; // 6M
108 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
113 case PHY_11BG_MIXED: // B/G Mixed
114 case PHY_11B: // B only
115 case PHY_11ABG_MIXED: // A/B/G Mixed
120 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
125 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
129 aryRates[0] = 0x0b; // 5.5M
130 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
134 aryRates[0] = 0x16; // 11M
135 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
139 aryRates[0] = 0x0c; // 6M
140 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
144 aryRates[0] = 0x12; // 9M
145 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
149 aryRates[0] = 0x18; // 12M
150 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
154 aryRates[0] = 0x24; // 18M
155 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
159 aryRates[0] = 0x30; // 24M
160 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
164 aryRates[0] = 0x48; // 36M
165 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
169 aryRates[0] = 0x60; // 48M
170 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
174 aryRates[0] = 0x6c; // 54M
175 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
180 if (pAdapter->CommonCfg.PhyMode == PHY_11B) { //B Only
181 aryRates[0] = 0x16; // 11Mbps
182 aryRates[1] = 0x0b; // 5.5Mbps
183 aryRates[2] = 0x04; // 2Mbps
184 aryRates[3] = 0x02; // 1Mbps
185 } else { //(B/G) Mixed or (A/B/G) Mixed
186 aryRates[0] = 0x6c; // 54Mbps
187 aryRates[1] = 0x60; // 48Mbps
188 aryRates[2] = 0x48; // 36Mbps
189 aryRates[3] = 0x30; // 24Mbps
190 aryRates[4] = 0x16; // 11Mbps
191 aryRates[5] = 0x0b; // 5.5Mbps
192 aryRates[6] = 0x04; // 2Mbps
193 aryRates[7] = 0x02; // 1Mbps
195 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
202 NdisZeroMemory(pAdapter->CommonCfg.DesireRate,
203 MAX_LEN_OF_SUPPORTED_RATES);
204 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates,
205 sizeof(NDIS_802_11_RATES));
206 DBGPRINT(RT_DEBUG_TRACE,
207 (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
208 pAdapter->CommonCfg.DesireRate[0],
209 pAdapter->CommonCfg.DesireRate[1],
210 pAdapter->CommonCfg.DesireRate[2],
211 pAdapter->CommonCfg.DesireRate[3],
212 pAdapter->CommonCfg.DesireRate[4],
213 pAdapter->CommonCfg.DesireRate[5],
214 pAdapter->CommonCfg.DesireRate[6],
215 pAdapter->CommonCfg.DesireRate[7]));
216 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
217 MlmeUpdateTxRates(pAdapter, FALSE, 0);
221 ========================================================================
227 pAd Pointer to our adapter
232 IRQL = DISPATCH_LEVEL
236 ========================================================================
238 VOID RTMPWPARemoveAllKeys(IN PRTMP_ADAPTER pAd)
243 DBGPRINT(RT_DEBUG_TRACE,
244 ("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n",
245 pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus));
246 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
247 // For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after
248 // Link up. And it will be replaced if user changed it.
249 if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
252 // For WPA-None, there is no need to remove it, since WinXP won't set it again after
253 // Link up. And it will be replaced if user changed it.
254 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
257 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
258 AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID);
260 // set all shared key mode as no-security.
261 for (i = 0; i < SHARE_KEY_NUM; i++) {
262 DBGPRINT(RT_DEBUG_TRACE,
263 ("remove %s key #%d\n",
264 CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i));
265 NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(CIPHER_KEY));
267 AsicRemoveSharedKeyEntry(pAd, BSS0, i);
269 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
273 ========================================================================
276 As STA's BSSID is a WC too, it uses shared key table.
277 This function write correct unicast TX key to ASIC WCID.
278 And we still make a copy in our MacTab.Content[BSSID_WCID].PairwiseKey.
279 Caller guarantee TKIP/AES always has keyidx = 0. (pairwise key)
280 Caller guarantee WEP calls this function when set Txkey, default key index=0~3.
283 pAd Pointer to our adapter
284 pKey Pointer to the where the key stored
287 NDIS_SUCCESS Add key successfully
289 IRQL = DISPATCH_LEVEL
293 ========================================================================
296 ========================================================================
298 Change NIC PHY mode. Re-association may be necessary. possible settings
299 include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
302 pAd - Pointer to our adapter
306 IRQL = DISPATCH_LEVEL
308 ========================================================================
310 VOID RTMPSetPhyMode(IN PRTMP_ADAPTER pAd, IN ULONG phymode)
313 // the selected phymode must be supported by the RF IC encoded in E2PROM
315 // if no change, do nothing
317 if (pAd->CommonCfg.PhyMode == phymode)
320 pAd->CommonCfg.PhyMode = (UCHAR) phymode;
322 DBGPRINT(RT_DEBUG_TRACE,
323 ("RTMPSetPhyMode : PhyMode=%d, channel=%d \n",
324 pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel));
326 BuildChannelList(pAd);
328 // sanity check user setting
329 for (i = 0; i < pAd->ChannelListNum; i++) {
330 if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel)
334 if (i == pAd->ChannelListNum) {
335 pAd->CommonCfg.Channel = FirstChannel(pAd);
336 DBGPRINT(RT_DEBUG_ERROR,
337 ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n",
338 pAd->CommonCfg.Channel));
341 NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
342 NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
343 NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
346 pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
347 pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
348 pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
349 pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
350 pAd->CommonCfg.SupRateLen = 4;
351 pAd->CommonCfg.ExtRateLen = 0;
352 pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps
353 pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps
354 pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
355 pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps
356 //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use
361 case PHY_11ABG_MIXED:
363 case PHY_11ABGN_MIXED:
364 case PHY_11BGN_MIXED:
366 pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
367 pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
368 pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
369 pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
370 pAd->CommonCfg.SupRate[4] = 0x12; // 9 mbps, in units of 0.5 Mbps
371 pAd->CommonCfg.SupRate[5] = 0x24; // 18 mbps, in units of 0.5 Mbps
372 pAd->CommonCfg.SupRate[6] = 0x48; // 36 mbps, in units of 0.5 Mbps
373 pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
374 pAd->CommonCfg.SupRateLen = 8;
375 pAd->CommonCfg.ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps
376 pAd->CommonCfg.ExtRate[1] = 0x18; // 12 mbps, in units of 0.5 Mbps
377 pAd->CommonCfg.ExtRate[2] = 0x30; // 24 mbps, in units of 0.5 Mbps
378 pAd->CommonCfg.ExtRate[3] = 0x60; // 48 mbps, in units of 0.5 Mbps
379 pAd->CommonCfg.ExtRateLen = 4;
380 pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps
381 pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps
382 pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
383 pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps
384 pAd->CommonCfg.DesireRate[4] = 12; // 6 mbps, in units of 0.5 Mbps
385 pAd->CommonCfg.DesireRate[5] = 18; // 9 mbps, in units of 0.5 Mbps
386 pAd->CommonCfg.DesireRate[6] = 24; // 12 mbps, in units of 0.5 Mbps
387 pAd->CommonCfg.DesireRate[7] = 36; // 18 mbps, in units of 0.5 Mbps
388 pAd->CommonCfg.DesireRate[8] = 48; // 24 mbps, in units of 0.5 Mbps
389 pAd->CommonCfg.DesireRate[9] = 72; // 36 mbps, in units of 0.5 Mbps
390 pAd->CommonCfg.DesireRate[10] = 96; // 48 mbps, in units of 0.5 Mbps
391 pAd->CommonCfg.DesireRate[11] = 108; // 54 mbps, in units of 0.5 Mbps
396 case PHY_11AGN_MIXED:
398 pAd->CommonCfg.SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
399 pAd->CommonCfg.SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
400 pAd->CommonCfg.SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
401 pAd->CommonCfg.SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
402 pAd->CommonCfg.SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
403 pAd->CommonCfg.SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
404 pAd->CommonCfg.SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
405 pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
406 pAd->CommonCfg.SupRateLen = 8;
407 pAd->CommonCfg.ExtRateLen = 0;
408 pAd->CommonCfg.DesireRate[0] = 12; // 6 mbps, in units of 0.5 Mbps
409 pAd->CommonCfg.DesireRate[1] = 18; // 9 mbps, in units of 0.5 Mbps
410 pAd->CommonCfg.DesireRate[2] = 24; // 12 mbps, in units of 0.5 Mbps
411 pAd->CommonCfg.DesireRate[3] = 36; // 18 mbps, in units of 0.5 Mbps
412 pAd->CommonCfg.DesireRate[4] = 48; // 24 mbps, in units of 0.5 Mbps
413 pAd->CommonCfg.DesireRate[5] = 72; // 36 mbps, in units of 0.5 Mbps
414 pAd->CommonCfg.DesireRate[6] = 96; // 48 mbps, in units of 0.5 Mbps
415 pAd->CommonCfg.DesireRate[7] = 108; // 54 mbps, in units of 0.5 Mbps
416 //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use
423 pAd->CommonCfg.BandState = UNKNOWN_BAND;
427 ========================================================================
429 Caller ensures we has 802.11n support.
430 Calls at setting HT from AP/STASetinformation
433 pAd - Pointer to our adapter
436 ========================================================================
438 VOID RTMPSetHT(IN PRTMP_ADAPTER pAd, IN OID_SET_HT_PHYMODE * pHTPhyMode)
444 UCHAR RxStream = pAd->CommonCfg.RxStream;
446 DBGPRINT(RT_DEBUG_TRACE,
447 ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n",
448 pHTPhyMode->HtMode, pHTPhyMode->ExtOffset, pHTPhyMode->MCS,
449 pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
451 // Don't zero supportedHyPhy structure.
452 RTMPZeroMemory(&pAd->CommonCfg.HtCapability,
453 sizeof(pAd->CommonCfg.HtCapability));
454 RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo,
455 sizeof(pAd->CommonCfg.AddHTInfo));
456 RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset,
457 sizeof(pAd->CommonCfg.NewExtChanOffset));
458 RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy,
459 sizeof(pAd->CommonCfg.DesiredHtPhy));
461 if (pAd->CommonCfg.bRdg) {
462 pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1;
463 pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1;
465 pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0;
466 pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0;
469 pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3;
470 pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3;
472 DBGPRINT(RT_DEBUG_TRACE,
473 ("RTMPSetHT : RxBAWinLimit = %d\n",
474 pAd->CommonCfg.BACapability.field.RxBAWinLimit));
476 // Mimo power save, A-MSDU size,
477 pAd->CommonCfg.DesiredHtPhy.AmsduEnable =
478 (USHORT) pAd->CommonCfg.BACapability.field.AmsduEnable;
479 pAd->CommonCfg.DesiredHtPhy.AmsduSize =
480 (UCHAR) pAd->CommonCfg.BACapability.field.AmsduSize;
481 pAd->CommonCfg.DesiredHtPhy.MimoPs =
482 (UCHAR) pAd->CommonCfg.BACapability.field.MMPSmode;
483 pAd->CommonCfg.DesiredHtPhy.MpduDensity =
484 (UCHAR) pAd->CommonCfg.BACapability.field.MpduDensity;
486 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize =
487 (USHORT) pAd->CommonCfg.BACapability.field.AmsduSize;
488 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs =
489 (USHORT) pAd->CommonCfg.BACapability.field.MMPSmode;
490 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity =
491 (UCHAR) pAd->CommonCfg.BACapability.field.MpduDensity;
493 DBGPRINT(RT_DEBUG_TRACE,
494 ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n",
495 pAd->CommonCfg.DesiredHtPhy.AmsduSize,
496 pAd->CommonCfg.DesiredHtPhy.MimoPs,
497 pAd->CommonCfg.DesiredHtPhy.MpduDensity,
498 pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor));
500 if (pHTPhyMode->HtMode == HTMODE_GF) {
501 pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1;
502 pAd->CommonCfg.DesiredHtPhy.GF = 1;
504 pAd->CommonCfg.DesiredHtPhy.GF = 0;
509 pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
510 pAd->CommonCfg.HtCapability.MCSSet[1] = 0x00;
514 pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
515 pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
519 pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
520 pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
521 pAd->CommonCfg.HtCapability.MCSSet[2] = 0xff;
525 if (pAd->CommonCfg.bForty_Mhz_Intolerant
526 && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40)) {
527 pHTPhyMode->BW = BW_20;
528 pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1;
531 if (pHTPhyMode->BW == BW_40) {
532 pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; // MCS 32
533 pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1;
534 if (pAd->CommonCfg.Channel <= 14)
535 pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1;
537 pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1;
538 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1;
539 pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset =
540 (pHTPhyMode->ExtOffset ==
541 EXTCHA_BELOW) ? (EXTCHA_BELOW) : EXTCHA_ABOVE;
542 // Set Regsiter for extension channel position.
543 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
544 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value);
545 if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW)) {
548 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
549 } else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE)) {
551 BBP3Value &= (~0x20);
552 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
554 // Turn on BBP 40MHz mode now only as AP .
555 // Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection.
556 if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd)
558 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
561 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
563 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value);
564 pAd->CommonCfg.BBPCurrentBW = BW_40;
567 pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0;
568 pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0;
569 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0;
570 pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE;
571 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
572 // Turn on BBP 20MHz mode by request here.
574 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
576 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
577 pAd->CommonCfg.BBPCurrentBW = BW_20;
581 if (pHTPhyMode->STBC == STBC_USE) {
582 pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1;
583 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1;
584 pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1;
585 pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1;
587 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
588 pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0;
591 if (pHTPhyMode->SHORTGI == GI_400) {
592 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1;
593 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1;
594 pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1;
595 pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1;
597 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0;
598 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0;
599 pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0;
600 pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0;
603 // We support link adaptation for unsolicit MCS feedback, set to 2.
604 pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; //MCSFBK_UNSOLICIT;
605 pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel;
606 // 1, the extension channel above the control channel.
608 // EDCA parameters used for AP's own transmission
609 if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) {
610 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
611 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
612 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
613 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
614 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
616 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
617 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
618 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
619 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
621 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6;
622 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10;
623 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
624 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
626 pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
627 pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
628 pAd->CommonCfg.APEdcaParm.Txop[2] = 94;
629 pAd->CommonCfg.APEdcaParm.Txop[3] = 47;
631 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
634 RTMPSetIndividualHT(pAd, 0);
640 ========================================================================
642 Caller ensures we has 802.11n support.
643 Calls at setting HT from AP/STASetinformation
646 pAd - Pointer to our adapter
649 ========================================================================
651 VOID RTMPSetIndividualHT(IN PRTMP_ADAPTER pAd, IN UCHAR apidx)
653 PRT_HT_PHY_INFO pDesired_ht_phy = NULL;
654 UCHAR TxStream = pAd->CommonCfg.TxStream;
655 UCHAR DesiredMcs = MCS_AUTO;
659 pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo;
661 pAd->StaCfg.DesiredTransmitSetting.field.MCS;
662 //pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE;
667 if (pDesired_ht_phy == NULL) {
668 DBGPRINT(RT_DEBUG_ERROR,
669 ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx));
672 RTMPZeroMemory(pDesired_ht_phy, sizeof(RT_HT_PHY_INFO));
674 DBGPRINT(RT_DEBUG_TRACE,
675 ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs));
676 // Check the validity of MCS
678 && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15))) {
679 DBGPRINT(RT_DEBUG_WARN,
680 ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n",
685 if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20)
686 && (DesiredMcs == MCS_32)) {
687 DBGPRINT(RT_DEBUG_WARN,
688 ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n"));
692 pDesired_ht_phy->bHtEnable = TRUE;
694 // Decide desired Tx MCS
697 if (DesiredMcs == MCS_AUTO) {
698 pDesired_ht_phy->MCSSet[0] = 0xff;
699 pDesired_ht_phy->MCSSet[1] = 0x00;
700 } else if (DesiredMcs <= MCS_7) {
701 pDesired_ht_phy->MCSSet[0] = 1 << DesiredMcs;
702 pDesired_ht_phy->MCSSet[1] = 0x00;
707 if (DesiredMcs == MCS_AUTO) {
708 pDesired_ht_phy->MCSSet[0] = 0xff;
709 pDesired_ht_phy->MCSSet[1] = 0xff;
710 } else if (DesiredMcs <= MCS_15) {
713 mode = DesiredMcs / 8;
715 pDesired_ht_phy->MCSSet[mode] =
716 (1 << (DesiredMcs - mode * 8));
721 if (DesiredMcs == MCS_AUTO) {
722 /* MCS0 ~ MCS23, 3 bytes */
723 pDesired_ht_phy->MCSSet[0] = 0xff;
724 pDesired_ht_phy->MCSSet[1] = 0xff;
725 pDesired_ht_phy->MCSSet[2] = 0xff;
726 } else if (DesiredMcs <= MCS_23) {
729 mode = DesiredMcs / 8;
731 pDesired_ht_phy->MCSSet[mode] =
732 (1 << (DesiredMcs - mode * 8));
737 if (pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40) {
738 if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32)
739 pDesired_ht_phy->MCSSet[4] = 0x1;
741 // update HT Rate setting
742 if (pAd->OpMode == OPMODE_STA)
743 MlmeUpdateHtTxRates(pAd, BSS0);
745 MlmeUpdateHtTxRates(pAd, apidx);
749 ========================================================================
751 Update HT IE from our capability.
754 Send all HT IE in beacon/probe rsp/assoc rsp/action frame.
756 ========================================================================
758 VOID RTMPUpdateHTIE(IN RT_HT_CAPABILITY * pRtHt,
760 OUT HT_CAPABILITY_IE * pHtCapability,
761 OUT ADD_HT_INFO_IE * pAddHtInfo)
763 RTMPZeroMemory(pHtCapability, sizeof(HT_CAPABILITY_IE));
764 RTMPZeroMemory(pAddHtInfo, sizeof(ADD_HT_INFO_IE));
766 pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth;
767 pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs;
768 pHtCapability->HtCapInfo.GF = pRtHt->GF;
769 pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20;
770 pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40;
771 pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC;
772 pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC;
773 pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize;
774 pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor;
775 pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity;
777 pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset;
778 pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth;
779 pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode;
780 pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent;
781 RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet */ pMcsSet, 4); // rt2860 only support MCS max=32, no need to copy all 16 uchar.
783 DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateHTIE <== \n"));
787 ========================================================================
789 Add Client security information into ASIC WCID table and IVEIV table.
791 ========================================================================
793 VOID RTMPAddWcidAttributeEntry(IN PRTMP_ADAPTER pAd,
796 IN UCHAR CipherAlg, IN MAC_TABLE_ENTRY * pEntry)
798 UINT32 WCIDAttri = 0;
806 DBGPRINT(RT_DEBUG_ERROR,
807 ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n",
811 // 1. In ADHOC mode, the AID is wcid number. And NO mesh link exists.
812 // 2. In Infra mode, the AID:1 MUST be wcid of infra STA.
813 // the AID:2~ assign to mesh link entry.
821 // Update WCID attribute table
822 offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
825 if (pEntry && pEntry->ValidAsMesh)
826 WCIDAttri = (CipherAlg << 1) | PAIRWISEKEYTABLE;
828 WCIDAttri = (CipherAlg << 1) | SHAREDKEYTABLE;
831 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
833 // Update IV/EIV table
834 offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);
837 if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC)
838 || (CipherAlg == CIPHER_AES)) {
839 // Eiv bit on. keyid always is 0 for pairwise key
840 IVEIV = (KeyIdx << 6) | 0x20;
842 // WEP KeyIdx is default tx key.
843 IVEIV = (KeyIdx << 6);
846 // For key index and ext IV bit, so only need to update the position(offset+3).
848 RTMP_IO_WRITE8(pAd, offset + 3, IVEIV);
849 #endif // RTMP_MAC_PCI //
851 RTUSBMultiWrite_OneByte(pAd, offset + 3, &IVEIV);
852 #endif // RTMP_MAC_USB //
854 DBGPRINT(RT_DEBUG_TRACE,
855 ("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",
856 Wcid, KeyIdx, CipherName[CipherAlg]));
857 DBGPRINT(RT_DEBUG_TRACE, (" WCIDAttri = 0x%x \n", WCIDAttri));
862 ==========================================================================
864 Parse encryption type
866 pAdapter Pointer to our adapter
867 wrq Pointer to the ioctl argument
873 ==========================================================================
875 PSTRING GetEncryptType(CHAR enc)
877 if (enc == Ndis802_11WEPDisabled)
879 if (enc == Ndis802_11WEPEnabled)
881 if (enc == Ndis802_11Encryption2Enabled)
883 if (enc == Ndis802_11Encryption3Enabled)
885 if (enc == Ndis802_11Encryption4Enabled)
891 PSTRING GetAuthMode(CHAR auth)
893 if (auth == Ndis802_11AuthModeOpen)
895 if (auth == Ndis802_11AuthModeShared)
897 if (auth == Ndis802_11AuthModeAutoSwitch)
899 if (auth == Ndis802_11AuthModeWPA)
901 if (auth == Ndis802_11AuthModeWPAPSK)
903 if (auth == Ndis802_11AuthModeWPANone)
905 if (auth == Ndis802_11AuthModeWPA2)
907 if (auth == Ndis802_11AuthModeWPA2PSK)
909 if (auth == Ndis802_11AuthModeWPA1WPA2)
911 if (auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)
912 return "WPA1PSKWPA2PSK";
917 INT SetCommonHT(IN PRTMP_ADAPTER pAd)
919 OID_SET_HT_PHYMODE SetHT;
921 if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
924 SetHT.PhyMode = pAd->CommonCfg.PhyMode;
925 SetHT.TransmitNo = ((UCHAR) pAd->Antenna.field.TxPath);
926 SetHT.HtMode = (UCHAR) pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
928 (UCHAR) pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
929 SetHT.MCS = MCS_AUTO;
930 SetHT.BW = (UCHAR) pAd->CommonCfg.RegTransmitSetting.field.BW;
931 SetHT.STBC = (UCHAR) pAd->CommonCfg.RegTransmitSetting.field.STBC;
932 SetHT.SHORTGI = (UCHAR) pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
934 RTMPSetHT(pAd, &SetHT);
939 PSTRING RTMPGetRalinkEncryModeStr(IN USHORT encryMode)
942 case Ndis802_11WEPDisabled:
944 case Ndis802_11WEPEnabled:
946 case Ndis802_11Encryption2Enabled:
948 case Ndis802_11Encryption3Enabled:
950 case Ndis802_11Encryption4Enabled: