1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. 4 * 5 * Contact Information: wlanfae <wlanfae@realtek.com> 6 */ 7 #include "rtllib.h" 8 #include "rtl819x_HT.h" 9 u8 MCS_FILTER_ALL[16] = { 10 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 11 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 12 }; 13 14 u8 MCS_FILTER_1SS[16] = { 15 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 16 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 17 ; 18 19 u16 MCS_DATA_RATE[2][2][77] = { 20 {{13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 21 260, 39, 78, 117, 234, 312, 351, 390, 52, 104, 156, 208, 312, 416, 22 468, 520, 0, 78, 104, 130, 117, 156, 195, 104, 130, 130, 156, 182, 23 182, 208, 156, 195, 195, 234, 273, 273, 312, 130, 156, 181, 156, 24 181, 208, 234, 208, 234, 260, 260, 286, 195, 234, 273, 234, 273, 25 312, 351, 312, 351, 390, 390, 429}, 26 {14, 29, 43, 58, 87, 116, 130, 144, 29, 58, 87, 116, 173, 231, 260, 289, 27 43, 87, 130, 173, 260, 347, 390, 433, 58, 116, 173, 231, 347, 462, 520, 28 578, 0, 87, 116, 144, 130, 173, 217, 116, 144, 144, 173, 202, 202, 231, 29 173, 217, 217, 260, 303, 303, 347, 144, 173, 202, 173, 202, 231, 260, 30 231, 260, 289, 289, 318, 217, 260, 303, 260, 303, 347, 390, 347, 390, 31 433, 433, 477} }, 32 {{27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 33 540, 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 34 864, 972, 1080, 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 35 378, 378, 432, 324, 405, 405, 486, 567, 567, 648, 270, 324, 378, 324, 36 378, 432, 486, 432, 486, 540, 540, 594, 405, 486, 567, 486, 567, 648, 37 729, 648, 729, 810, 810, 891}, 38 {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 39 600, 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 40 960, 1080, 1200, 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 41 420, 420, 480, 360, 450, 450, 540, 630, 630, 720, 300, 360, 420, 360, 42 420, 480, 540, 480, 540, 600, 600, 660, 450, 540, 630, 540, 630, 720, 43 810, 720, 810, 900, 900, 990} } 44 }; 45 46 static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf}; 47 48 static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70}; 49 50 static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e}; 51 52 static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f}; 53 54 static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf}; 55 56 static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc}; 57 58 static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e}; 59 60 static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02}; 61 62 static u8 DLINK_ATHEROS_1[3] = {0x00, 0x1c, 0xf0}; 63 64 static u8 DLINK_ATHEROS_2[3] = {0x00, 0x21, 0x91}; 65 66 static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94}; 67 68 static u8 LINKSYS_MARVELL_4400N[3] = {0x00, 0x14, 0xa4}; 69 70 void HTUpdateDefaultSetting(struct rtllib_device *ieee) 71 { 72 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 73 74 pHTInfo->bAcceptAddbaReq = 1; 75 76 pHTInfo->bRegShortGI20MHz = 1; 77 pHTInfo->bRegShortGI40MHz = 1; 78 79 pHTInfo->bRegBW40MHz = 1; 80 81 if (pHTInfo->bRegBW40MHz) 82 pHTInfo->bRegSuppCCK = 1; 83 else 84 pHTInfo->bRegSuppCCK = true; 85 86 pHTInfo->nAMSDU_MaxSize = 7935UL; 87 pHTInfo->bAMSDU_Support = 0; 88 89 pHTInfo->bAMPDUEnable = 1; 90 pHTInfo->AMPDU_Factor = 2; 91 pHTInfo->MPDU_Density = 0; 92 93 pHTInfo->SelfMimoPs = 3; 94 if (pHTInfo->SelfMimoPs == 2) 95 pHTInfo->SelfMimoPs = 3; 96 ieee->bTxDisableRateFallBack = 0; 97 ieee->bTxUseDriverAssingedRate = 0; 98 99 ieee->bTxEnableFwCalcDur = 1; 100 101 pHTInfo->bRegRT2RTAggregation = 1; 102 103 pHTInfo->bRegRxReorderEnable = 1; 104 pHTInfo->RxReorderWinSize = 64; 105 pHTInfo->RxReorderPendingTime = 30; 106 } 107 108 static u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate) 109 { 110 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 111 112 u8 is40MHz = (pHTInfo->bCurBW40MHz) ? 1 : 0; 113 u8 isShortGI = (pHTInfo->bCurBW40MHz) ? 114 ((pHTInfo->bCurShortGI40MHz) ? 1 : 0) : 115 ((pHTInfo->bCurShortGI20MHz) ? 1 : 0); 116 return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)]; 117 } 118 119 u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate) 120 { 121 u16 CCKOFDMRate[12] = {0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 122 0x24, 0x30, 0x48, 0x60, 0x6c}; 123 u8 is40MHz = 0; 124 u8 isShortGI = 0; 125 126 if (nDataRate < 12) 127 return CCKOFDMRate[nDataRate]; 128 if (nDataRate >= 0x10 && nDataRate <= 0x1f) { 129 is40MHz = 0; 130 isShortGI = 0; 131 } else if (nDataRate >= 0x20 && nDataRate <= 0x2f) { 132 is40MHz = 1; 133 isShortGI = 0; 134 } else if (nDataRate >= 0x30 && nDataRate <= 0x3f) { 135 is40MHz = 0; 136 isShortGI = 1; 137 } else if (nDataRate >= 0x40 && nDataRate <= 0x4f) { 138 is40MHz = 1; 139 isShortGI = 1; 140 } 141 return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate & 0xf]; 142 } 143 144 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee) 145 { 146 bool retValue = false; 147 struct rtllib_network *net = &ieee->current_network; 148 149 if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) || 150 (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) || 151 (memcmp(net->bssid, PCI_RALINK, 3) == 0) || 152 (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) || 153 (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) || 154 (net->ralink_cap_exist)) 155 retValue = true; 156 else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) || 157 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) || 158 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) || 159 (net->broadcom_cap_exist)) 160 retValue = true; 161 else if (net->bssht.bd_rt2rt_aggregation) 162 retValue = true; 163 else 164 retValue = false; 165 166 return retValue; 167 } 168 169 static void HTIOTPeerDetermine(struct rtllib_device *ieee) 170 { 171 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 172 struct rtllib_network *net = &ieee->current_network; 173 174 if (net->bssht.bd_rt2rt_aggregation) { 175 pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK; 176 if (net->bssht.rt2rt_ht_mode & RT_HT_CAP_USE_92SE) 177 pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK_92SE; 178 if (net->bssht.rt2rt_ht_mode & RT_HT_CAP_USE_SOFTAP) 179 pHTInfo->IOTPeer = HT_IOT_PEER_92U_SOFTAP; 180 } else if (net->broadcom_cap_exist) { 181 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM; 182 } else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) || 183 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) || 184 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)) { 185 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM; 186 } else if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) || 187 (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) || 188 (memcmp(net->bssid, PCI_RALINK, 3) == 0) || 189 (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) || 190 (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) || 191 net->ralink_cap_exist) { 192 pHTInfo->IOTPeer = HT_IOT_PEER_RALINK; 193 } else if ((net->atheros_cap_exist) || 194 (memcmp(net->bssid, DLINK_ATHEROS_1, 3) == 0) || 195 (memcmp(net->bssid, DLINK_ATHEROS_2, 3) == 0)) { 196 pHTInfo->IOTPeer = HT_IOT_PEER_ATHEROS; 197 } else if ((memcmp(net->bssid, CISCO_BROADCOM, 3) == 0) || 198 net->cisco_cap_exist) { 199 pHTInfo->IOTPeer = HT_IOT_PEER_CISCO; 200 } else if ((memcmp(net->bssid, LINKSYS_MARVELL_4400N, 3) == 0) || 201 net->marvell_cap_exist) { 202 pHTInfo->IOTPeer = HT_IOT_PEER_MARVELL; 203 } else if (net->airgo_cap_exist) { 204 pHTInfo->IOTPeer = HT_IOT_PEER_AIRGO; 205 } else { 206 pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN; 207 } 208 209 netdev_dbg(ieee->dev, "IOTPEER: %x\n", pHTInfo->IOTPeer); 210 } 211 212 static u8 HTIOTActIsDisableMCS14(struct rtllib_device *ieee, u8 *PeerMacAddr) 213 { 214 return 0; 215 } 216 217 218 static bool HTIOTActIsDisableMCS15(struct rtllib_device *ieee) 219 { 220 return false; 221 } 222 223 static bool HTIOTActIsDisableMCSTwoSpatialStream(struct rtllib_device *ieee) 224 { 225 return false; 226 } 227 228 static u8 HTIOTActIsDisableEDCATurbo(struct rtllib_device *ieee, 229 u8 *PeerMacAddr) 230 { 231 return false; 232 } 233 234 static u8 HTIOTActIsMgntUseCCK6M(struct rtllib_device *ieee, 235 struct rtllib_network *network) 236 { 237 u8 retValue = 0; 238 239 240 if (ieee->pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM) 241 retValue = 1; 242 243 return retValue; 244 } 245 246 static u8 HTIOTActIsCCDFsync(struct rtllib_device *ieee) 247 { 248 u8 retValue = 0; 249 250 if (ieee->pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM) 251 retValue = 1; 252 return retValue; 253 } 254 255 static void HTIOTActDetermineRaFunc(struct rtllib_device *ieee, bool bPeerRx2ss) 256 { 257 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 258 259 pHTInfo->IOTRaFunc &= HT_IOT_RAFUNC_DISABLE_ALL; 260 261 if (pHTInfo->IOTPeer == HT_IOT_PEER_RALINK && !bPeerRx2ss) 262 pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_PEER_1R; 263 264 if (pHTInfo->IOTAction & HT_IOT_ACT_AMSDU_ENABLE) 265 pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_TX_AMSDU; 266 } 267 268 void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo) 269 { 270 pHTInfo->IOTAction = 0; 271 pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN; 272 pHTInfo->IOTRaFunc = 0; 273 } 274 275 void HTConstructCapabilityElement(struct rtllib_device *ieee, u8 *posHTCap, 276 u8 *len, u8 IsEncrypt, bool bAssoc) 277 { 278 struct rt_hi_throughput *pHT = ieee->pHTInfo; 279 struct ht_capab_ele *pCapELE = NULL; 280 281 if ((posHTCap == NULL) || (pHT == NULL)) { 282 netdev_warn(ieee->dev, 283 "%s(): posHTCap and pHTInfo are null\n", __func__); 284 return; 285 } 286 memset(posHTCap, 0, *len); 287 288 if ((bAssoc) && (pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)) { 289 u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; 290 291 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap)); 292 pCapELE = (struct ht_capab_ele *)&(posHTCap[4]); 293 *len = 30 + 2; 294 } else { 295 pCapELE = (struct ht_capab_ele *)posHTCap; 296 *len = 26 + 2; 297 } 298 299 pCapELE->AdvCoding = 0; 300 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) 301 pCapELE->ChlWidth = 0; 302 else 303 pCapELE->ChlWidth = (pHT->bRegBW40MHz ? 1 : 0); 304 305 pCapELE->MimoPwrSave = pHT->SelfMimoPs; 306 pCapELE->GreenField = 0; 307 pCapELE->ShortGI20Mhz = 1; 308 pCapELE->ShortGI40Mhz = 1; 309 310 pCapELE->TxSTBC = 1; 311 pCapELE->RxSTBC = 0; 312 pCapELE->DelayBA = 0; 313 pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0; 314 pCapELE->DssCCk = ((pHT->bRegBW40MHz) ? (pHT->bRegSuppCCK ? 1 : 0) : 0); 315 pCapELE->PSMP = 0; 316 pCapELE->LSigTxopProtect = 0; 317 318 319 netdev_dbg(ieee->dev, 320 "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", 321 pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk); 322 323 if (IsEncrypt) { 324 pCapELE->MPDUDensity = 7; 325 pCapELE->MaxRxAMPDUFactor = 2; 326 } else { 327 pCapELE->MaxRxAMPDUFactor = 3; 328 pCapELE->MPDUDensity = 0; 329 } 330 331 memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16); 332 memset(&pCapELE->ExtHTCapInfo, 0, 2); 333 memset(pCapELE->TxBFCap, 0, 4); 334 335 pCapELE->ASCap = 0; 336 337 if (bAssoc) { 338 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15) 339 pCapELE->MCS[1] &= 0x7f; 340 341 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14) 342 pCapELE->MCS[1] &= 0xbf; 343 344 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS) 345 pCapELE->MCS[1] &= 0x00; 346 347 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_RX_40MHZ_SHORT_GI) 348 pCapELE->ShortGI40Mhz = 0; 349 350 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) { 351 pCapELE->ChlWidth = 0; 352 pCapELE->MCS[1] = 0; 353 } 354 } 355 } 356 357 void HTConstructInfoElement(struct rtllib_device *ieee, u8 *posHTInfo, 358 u8 *len, u8 IsEncrypt) 359 { 360 struct rt_hi_throughput *pHT = ieee->pHTInfo; 361 struct ht_info_ele *pHTInfoEle = (struct ht_info_ele *)posHTInfo; 362 363 if ((posHTInfo == NULL) || (pHTInfoEle == NULL)) { 364 netdev_warn(ieee->dev, 365 "%s(): posHTInfo and pHTInfoEle are null\n", 366 __func__); 367 return; 368 } 369 370 memset(posHTInfo, 0, *len); 371 if ((ieee->iw_mode == IW_MODE_ADHOC) || 372 (ieee->iw_mode == IW_MODE_MASTER)) { 373 pHTInfoEle->ControlChl = ieee->current_network.channel; 374 pHTInfoEle->ExtChlOffset = ((!pHT->bRegBW40MHz) ? 375 HT_EXTCHNL_OFFSET_NO_EXT : 376 (ieee->current_network.channel <= 6) 377 ? HT_EXTCHNL_OFFSET_UPPER : 378 HT_EXTCHNL_OFFSET_LOWER); 379 pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz; 380 pHTInfoEle->RIFS = 0; 381 pHTInfoEle->PSMPAccessOnly = 0; 382 pHTInfoEle->SrvIntGranularity = 0; 383 pHTInfoEle->OptMode = pHT->CurrentOpMode; 384 pHTInfoEle->NonGFDevPresent = 0; 385 pHTInfoEle->DualBeacon = 0; 386 pHTInfoEle->SecondaryBeacon = 0; 387 pHTInfoEle->LSigTxopProtectFull = 0; 388 pHTInfoEle->PcoActive = 0; 389 pHTInfoEle->PcoPhase = 0; 390 391 memset(pHTInfoEle->BasicMSC, 0, 16); 392 393 394 *len = 22 + 2; 395 396 } else { 397 *len = 0; 398 } 399 } 400 401 void HTConstructRT2RTAggElement(struct rtllib_device *ieee, u8 *posRT2RTAgg, 402 u8 *len) 403 { 404 if (posRT2RTAgg == NULL) { 405 netdev_warn(ieee->dev, "%s(): posRT2RTAgg is null\n", __func__); 406 return; 407 } 408 memset(posRT2RTAgg, 0, *len); 409 *posRT2RTAgg++ = 0x00; 410 *posRT2RTAgg++ = 0xe0; 411 *posRT2RTAgg++ = 0x4c; 412 *posRT2RTAgg++ = 0x02; 413 *posRT2RTAgg++ = 0x01; 414 415 *posRT2RTAgg = 0x30; 416 417 if (ieee->bSupportRemoteWakeUp) 418 *posRT2RTAgg |= RT_HT_CAP_USE_WOW; 419 420 *len = 6 + 2; 421 } 422 423 static u8 HT_PickMCSRate(struct rtllib_device *ieee, u8 *pOperateMCS) 424 { 425 u8 i; 426 427 if (pOperateMCS == NULL) { 428 netdev_warn(ieee->dev, "%s(): pOperateMCS is null\n", __func__); 429 return false; 430 } 431 432 switch (ieee->mode) { 433 case IEEE_A: 434 case IEEE_B: 435 case IEEE_G: 436 for (i = 0; i <= 15; i++) 437 pOperateMCS[i] = 0; 438 break; 439 case IEEE_N_24G: 440 case IEEE_N_5G: 441 pOperateMCS[0] &= RATE_ADPT_1SS_MASK; 442 pOperateMCS[1] &= RATE_ADPT_2SS_MASK; 443 pOperateMCS[3] &= RATE_ADPT_MCS32_MASK; 444 break; 445 default: 446 break; 447 } 448 449 return true; 450 } 451 452 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet, 453 u8 *pMCSFilter) 454 { 455 u8 i, j; 456 u8 bitMap; 457 u8 mcsRate = 0; 458 u8 availableMcsRate[16]; 459 460 if (pMCSRateSet == NULL || pMCSFilter == NULL) { 461 netdev_warn(ieee->dev, 462 "%s(): pMCSRateSet and pMCSFilter are null\n", 463 __func__); 464 return false; 465 } 466 for (i = 0; i < 16; i++) 467 availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i]; 468 469 for (i = 0; i < 16; i++) { 470 if (availableMcsRate[i] != 0) 471 break; 472 } 473 if (i == 16) 474 return false; 475 476 for (i = 0; i < 16; i++) { 477 if (availableMcsRate[i] != 0) { 478 bitMap = availableMcsRate[i]; 479 for (j = 0; j < 8; j++) { 480 if ((bitMap % 2) != 0) { 481 if (HTMcsToDataRate(ieee, (8 * i + j)) > 482 HTMcsToDataRate(ieee, mcsRate)) 483 mcsRate = 8 * i + j; 484 } 485 bitMap >>= 1; 486 } 487 } 488 } 489 return mcsRate | 0x80; 490 } 491 492 static u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS, 493 u8 *pOperateMCS) 494 { 495 u8 i; 496 497 for (i = 0; i <= 15; i++) 498 pOperateMCS[i] = ieee->Regdot11TxHTOperationalRateSet[i] & 499 pSupportMCS[i]; 500 501 HT_PickMCSRate(ieee, pOperateMCS); 502 503 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) 504 pOperateMCS[1] = 0; 505 506 for (i = 2; i <= 15; i++) 507 pOperateMCS[i] = 0; 508 509 return true; 510 } 511 512 void HTSetConnectBwMode(struct rtllib_device *ieee, 513 enum ht_channel_width Bandwidth, 514 enum ht_extchnl_offset Offset); 515 516 void HTOnAssocRsp(struct rtllib_device *ieee) 517 { 518 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 519 struct ht_capab_ele *pPeerHTCap = NULL; 520 struct ht_info_ele *pPeerHTInfo = NULL; 521 u16 nMaxAMSDUSize = 0; 522 u8 *pMcsFilter = NULL; 523 524 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; 525 static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; 526 527 if (!pHTInfo->bCurrentHTSupport) { 528 netdev_warn(ieee->dev, "%s(): HT_DISABLE\n", __func__); 529 return; 530 } 531 netdev_dbg(ieee->dev, "%s(): HT_ENABLE\n", __func__); 532 533 if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap))) 534 pPeerHTCap = (struct ht_capab_ele *)(&pHTInfo->PeerHTCapBuf[4]); 535 else 536 pPeerHTCap = (struct ht_capab_ele *)(pHTInfo->PeerHTCapBuf); 537 538 if (!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo))) 539 pPeerHTInfo = (struct ht_info_ele *) 540 (&pHTInfo->PeerHTInfoBuf[4]); 541 else 542 pPeerHTInfo = (struct ht_info_ele *)(pHTInfo->PeerHTInfoBuf); 543 544 545 #ifdef VERBOSE_DEBUG 546 print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE, 547 pPeerHTCap, sizeof(struct ht_capab_ele)); 548 #endif 549 HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth), 550 (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset)); 551 pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ? 552 true : false); 553 554 pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ? 555 ((pPeerHTCap->ShortGI20Mhz == 1) ? 556 true : false) : false); 557 pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ? 558 ((pPeerHTCap->ShortGI40Mhz == 1) ? 559 true : false) : false); 560 561 pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ? 562 ((pPeerHTCap->DssCCk == 1) ? true : 563 false) : false); 564 565 566 pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support; 567 568 nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize == 0) ? 3839 : 7935; 569 570 if (pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize) 571 pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize; 572 else 573 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize; 574 575 pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable; 576 if (ieee->rtllib_ap_sec_type && 577 (ieee->rtllib_ap_sec_type(ieee) & (SEC_ALG_WEP | SEC_ALG_TKIP))) { 578 if ((pHTInfo->IOTPeer == HT_IOT_PEER_ATHEROS) || 579 (pHTInfo->IOTPeer == HT_IOT_PEER_UNKNOWN)) 580 pHTInfo->bCurrentAMPDUEnable = false; 581 } 582 583 if (!pHTInfo->bRegRT2RTAggregation) { 584 if (pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor) 585 pHTInfo->CurrentAMPDUFactor = 586 pPeerHTCap->MaxRxAMPDUFactor; 587 else 588 pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor; 589 590 } else { 591 if (ieee->current_network.bssht.bd_rt2rt_aggregation) { 592 if (ieee->pairwise_key_type != KEY_TYPE_NA) 593 pHTInfo->CurrentAMPDUFactor = 594 pPeerHTCap->MaxRxAMPDUFactor; 595 else 596 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K; 597 } else { 598 if (pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K) 599 pHTInfo->CurrentAMPDUFactor = 600 pPeerHTCap->MaxRxAMPDUFactor; 601 else 602 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K; 603 } 604 } 605 if (pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity) 606 pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density; 607 else 608 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity; 609 if (pHTInfo->IOTAction & HT_IOT_ACT_TX_USE_AMSDU_8K) { 610 pHTInfo->bCurrentAMPDUEnable = false; 611 pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE; 612 pHTInfo->ForcedAMSDUMaxSize = 7935; 613 } 614 pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable; 615 616 if (pPeerHTCap->MCS[0] == 0) 617 pPeerHTCap->MCS[0] = 0xff; 618 619 HTIOTActDetermineRaFunc(ieee, ((pPeerHTCap->MCS[1]) != 0)); 620 621 HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet); 622 623 pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave; 624 if (pHTInfo->PeerMimoPs == MIMO_PS_STATIC) 625 pMcsFilter = MCS_FILTER_1SS; 626 else 627 pMcsFilter = MCS_FILTER_ALL; 628 ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, 629 ieee->dot11HTOperationalRateSet, pMcsFilter); 630 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate; 631 632 pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode; 633 } 634 635 void HTInitializeHTInfo(struct rtllib_device *ieee) 636 { 637 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 638 639 pHTInfo->bCurrentHTSupport = false; 640 641 pHTInfo->bCurBW40MHz = false; 642 pHTInfo->bCurTxBW40MHz = false; 643 644 pHTInfo->bCurShortGI20MHz = false; 645 pHTInfo->bCurShortGI40MHz = false; 646 pHTInfo->bForcedShortGI = false; 647 648 pHTInfo->bCurSuppCCK = true; 649 650 pHTInfo->bCurrent_AMSDU_Support = false; 651 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize; 652 pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density; 653 pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor; 654 655 memset((void *)(&(pHTInfo->SelfHTCap)), 0, 656 sizeof(pHTInfo->SelfHTCap)); 657 memset((void *)(&(pHTInfo->SelfHTInfo)), 0, 658 sizeof(pHTInfo->SelfHTInfo)); 659 memset((void *)(&(pHTInfo->PeerHTCapBuf)), 0, 660 sizeof(pHTInfo->PeerHTCapBuf)); 661 memset((void *)(&(pHTInfo->PeerHTInfoBuf)), 0, 662 sizeof(pHTInfo->PeerHTInfoBuf)); 663 664 pHTInfo->bSwBwInProgress = false; 665 666 pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE; 667 668 pHTInfo->bCurrentRT2RTAggregation = false; 669 pHTInfo->bCurrentRT2RTLongSlotTime = false; 670 pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0; 671 672 pHTInfo->IOTPeer = 0; 673 pHTInfo->IOTAction = 0; 674 pHTInfo->IOTRaFunc = 0; 675 676 { 677 u8 *RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]); 678 679 RegHTSuppRateSets[0] = 0xFF; 680 RegHTSuppRateSets[1] = 0xFF; 681 RegHTSuppRateSets[4] = 0x01; 682 } 683 } 684 685 void HTInitializeBssDesc(struct bss_ht *pBssHT) 686 { 687 pBssHT->bd_support_ht = false; 688 memset(pBssHT->bd_ht_cap_buf, 0, sizeof(pBssHT->bd_ht_cap_buf)); 689 pBssHT->bd_ht_cap_len = 0; 690 memset(pBssHT->bd_ht_info_buf, 0, sizeof(pBssHT->bd_ht_info_buf)); 691 pBssHT->bd_ht_info_len = 0; 692 693 pBssHT->bd_ht_spec_ver = HT_SPEC_VER_IEEE; 694 695 pBssHT->bd_rt2rt_aggregation = false; 696 pBssHT->bd_rt2rt_long_slot_time = false; 697 pBssHT->rt2rt_ht_mode = (enum rt_ht_capability)0; 698 } 699 700 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee, 701 struct rtllib_network *pNetwork) 702 { 703 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 704 u8 bIOTAction = 0; 705 706 /* unmark bEnableHT flag here is the same reason why unmarked in 707 * function rtllib_softmac_new_net. WB 2008.09.10 708 */ 709 if (pNetwork->bssht.bd_support_ht) { 710 pHTInfo->bCurrentHTSupport = true; 711 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bd_ht_spec_ver; 712 713 if (pNetwork->bssht.bd_ht_cap_len > 0 && 714 pNetwork->bssht.bd_ht_cap_len <= sizeof(pHTInfo->PeerHTCapBuf)) 715 memcpy(pHTInfo->PeerHTCapBuf, 716 pNetwork->bssht.bd_ht_cap_buf, 717 pNetwork->bssht.bd_ht_cap_len); 718 719 if (pNetwork->bssht.bd_ht_info_len > 0 && 720 pNetwork->bssht.bd_ht_info_len <= 721 sizeof(pHTInfo->PeerHTInfoBuf)) 722 memcpy(pHTInfo->PeerHTInfoBuf, 723 pNetwork->bssht.bd_ht_info_buf, 724 pNetwork->bssht.bd_ht_info_len); 725 726 if (pHTInfo->bRegRT2RTAggregation) { 727 pHTInfo->bCurrentRT2RTAggregation = 728 pNetwork->bssht.bd_rt2rt_aggregation; 729 pHTInfo->bCurrentRT2RTLongSlotTime = 730 pNetwork->bssht.bd_rt2rt_long_slot_time; 731 pHTInfo->RT2RT_HT_Mode = pNetwork->bssht.rt2rt_ht_mode; 732 } else { 733 pHTInfo->bCurrentRT2RTAggregation = false; 734 pHTInfo->bCurrentRT2RTLongSlotTime = false; 735 pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0; 736 } 737 738 HTIOTPeerDetermine(ieee); 739 740 pHTInfo->IOTAction = 0; 741 bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid); 742 if (bIOTAction) 743 pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14; 744 745 bIOTAction = HTIOTActIsDisableMCS15(ieee); 746 if (bIOTAction) 747 pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15; 748 749 bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee); 750 if (bIOTAction) 751 pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS; 752 753 754 bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid); 755 if (bIOTAction) 756 pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO; 757 758 bIOTAction = HTIOTActIsMgntUseCCK6M(ieee, pNetwork); 759 if (bIOTAction) 760 pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M; 761 bIOTAction = HTIOTActIsCCDFsync(ieee); 762 if (bIOTAction) 763 pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC; 764 } else { 765 pHTInfo->bCurrentHTSupport = false; 766 pHTInfo->bCurrentRT2RTAggregation = false; 767 pHTInfo->bCurrentRT2RTLongSlotTime = false; 768 pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0; 769 770 pHTInfo->IOTAction = 0; 771 pHTInfo->IOTRaFunc = 0; 772 } 773 } 774 775 void HT_update_self_and_peer_setting(struct rtllib_device *ieee, 776 struct rtllib_network *pNetwork) 777 { 778 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 779 struct ht_info_ele *pPeerHTInfo = 780 (struct ht_info_ele *)pNetwork->bssht.bd_ht_info_buf; 781 782 if (pHTInfo->bCurrentHTSupport) { 783 if (pNetwork->bssht.bd_ht_info_len != 0) 784 pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode; 785 } 786 } 787 EXPORT_SYMBOL(HT_update_self_and_peer_setting); 788 789 void HTUseDefaultSetting(struct rtllib_device *ieee) 790 { 791 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 792 793 if (pHTInfo->bEnableHT) { 794 pHTInfo->bCurrentHTSupport = true; 795 pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK; 796 797 pHTInfo->bCurBW40MHz = pHTInfo->bRegBW40MHz; 798 pHTInfo->bCurShortGI20MHz = pHTInfo->bRegShortGI20MHz; 799 800 pHTInfo->bCurShortGI40MHz = pHTInfo->bRegShortGI40MHz; 801 802 if (ieee->iw_mode == IW_MODE_ADHOC) 803 ieee->current_network.qos_data.active = 804 ieee->current_network.qos_data.supported; 805 pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support; 806 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize; 807 808 pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable; 809 pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor; 810 811 pHTInfo->CurrentMPDUDensity = pHTInfo->CurrentMPDUDensity; 812 813 HTFilterMCSRate(ieee, ieee->Regdot11TxHTOperationalRateSet, 814 ieee->dot11HTOperationalRateSet); 815 ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, 816 ieee->dot11HTOperationalRateSet, 817 MCS_FILTER_ALL); 818 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate; 819 820 } else { 821 pHTInfo->bCurrentHTSupport = false; 822 } 823 } 824 825 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame) 826 { 827 if (ieee->pHTInfo->bCurrentHTSupport) { 828 if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) { 829 netdev_dbg(ieee->dev, "HT CONTROL FILED EXIST!!\n"); 830 return true; 831 } 832 } 833 return false; 834 } 835 836 static void HTSetConnectBwModeCallback(struct rtllib_device *ieee) 837 { 838 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 839 840 if (pHTInfo->bCurBW40MHz) { 841 if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER) 842 ieee->set_chan(ieee->dev, 843 ieee->current_network.channel + 2); 844 else if (pHTInfo->CurSTAExtChnlOffset == 845 HT_EXTCHNL_OFFSET_LOWER) 846 ieee->set_chan(ieee->dev, 847 ieee->current_network.channel - 2); 848 else 849 ieee->set_chan(ieee->dev, 850 ieee->current_network.channel); 851 852 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, 853 pHTInfo->CurSTAExtChnlOffset); 854 } else { 855 ieee->set_chan(ieee->dev, ieee->current_network.channel); 856 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, 857 HT_EXTCHNL_OFFSET_NO_EXT); 858 } 859 860 pHTInfo->bSwBwInProgress = false; 861 } 862 863 void HTSetConnectBwMode(struct rtllib_device *ieee, 864 enum ht_channel_width Bandwidth, 865 enum ht_extchnl_offset Offset) 866 { 867 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 868 869 if (!pHTInfo->bRegBW40MHz) 870 return; 871 872 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) 873 Bandwidth = HT_CHANNEL_WIDTH_20; 874 875 if (pHTInfo->bSwBwInProgress) { 876 pr_info("%s: bSwBwInProgress!!\n", __func__); 877 return; 878 } 879 if (Bandwidth == HT_CHANNEL_WIDTH_20_40) { 880 if (ieee->current_network.channel < 2 && 881 Offset == HT_EXTCHNL_OFFSET_LOWER) 882 Offset = HT_EXTCHNL_OFFSET_NO_EXT; 883 if (Offset == HT_EXTCHNL_OFFSET_UPPER || 884 Offset == HT_EXTCHNL_OFFSET_LOWER) { 885 pHTInfo->bCurBW40MHz = true; 886 pHTInfo->CurSTAExtChnlOffset = Offset; 887 } else { 888 pHTInfo->bCurBW40MHz = false; 889 pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; 890 } 891 } else { 892 pHTInfo->bCurBW40MHz = false; 893 pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; 894 } 895 896 netdev_dbg(ieee->dev, "%s():pHTInfo->bCurBW40MHz:%x\n", __func__, 897 pHTInfo->bCurBW40MHz); 898 899 pHTInfo->bSwBwInProgress = true; 900 901 HTSetConnectBwModeCallback(ieee); 902 } 903