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" 9u8 MCS_FILTER_ALL[16] = { 10 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 11 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 12}; 13 14u8 MCS_FILTER_1SS[16] = { 15 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 16 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 17; 18 19u16 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 46static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf}; 47 48static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70}; 49 50static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e}; 51 52static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f}; 53 54static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf}; 55 56static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc}; 57 58static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e}; 59 60static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02}; 61 62static u8 DLINK_ATHEROS_1[3] = {0x00, 0x1c, 0xf0}; 63 64static u8 DLINK_ATHEROS_2[3] = {0x00, 0x21, 0x91}; 65 66static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94}; 67 68static u8 LINKSYS_MARVELL_4400N[3] = {0x00, 0x14, 0xa4}; 69 70void ht_update_default_setting(struct rtllib_device *ieee) 71{ 72 struct rt_hi_throughput *ht_info = ieee->ht_info; 73 74 ht_info->ampdu_enable = 1; 75 ht_info->ampdu_factor = 2; 76 77 ieee->tx_dis_rate_fallback = 0; 78 ieee->tx_use_drv_assinged_rate = 0; 79 80 ieee->tx_enable_fw_calc_dur = 1; 81 82 ht_info->rx_reorder_win_size = 64; 83 ht_info->rx_reorder_pending_time = 30; 84} 85 86static u16 ht_mcs_to_data_rate(struct rtllib_device *ieee, u8 mcs_rate) 87{ 88 struct rt_hi_throughput *ht_info = ieee->ht_info; 89 90 u8 is40MHz = (ht_info->cur_bw_40mhz) ? 1 : 0; 91 u8 isShortGI = (ht_info->cur_bw_40mhz) ? 92 ((ht_info->cur_short_gi_40mhz) ? 1 : 0) : 93 ((ht_info->cur_short_gi_20mhz) ? 1 : 0); 94 return MCS_DATA_RATE[is40MHz][isShortGI][(mcs_rate & 0x7f)]; 95} 96 97u16 tx_count_to_data_rate(struct rtllib_device *ieee, u8 data_rate) 98{ 99 u16 cck_of_dm_rate[12] = {0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 100 0x24, 0x30, 0x48, 0x60, 0x6c}; 101 u8 is40MHz = 0; 102 u8 isShortGI = 0; 103 104 if (data_rate < 12) 105 return cck_of_dm_rate[data_rate]; 106 if (data_rate >= 0x10 && data_rate <= 0x1f) { 107 is40MHz = 0; 108 isShortGI = 0; 109 } else if (data_rate >= 0x20 && data_rate <= 0x2f) { 110 is40MHz = 1; 111 isShortGI = 0; 112 } else if (data_rate >= 0x30 && data_rate <= 0x3f) { 113 is40MHz = 0; 114 isShortGI = 1; 115 } else if (data_rate >= 0x40 && data_rate <= 0x4f) { 116 is40MHz = 1; 117 isShortGI = 1; 118 } 119 return MCS_DATA_RATE[is40MHz][isShortGI][data_rate & 0xf]; 120} 121 122bool is_ht_half_nmode_aps(struct rtllib_device *ieee) 123{ 124 bool retValue = false; 125 struct rtllib_network *net = &ieee->current_network; 126 127 if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) || 128 (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) || 129 (memcmp(net->bssid, PCI_RALINK, 3) == 0) || 130 (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) || 131 (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) || 132 (net->ralink_cap_exist)) 133 retValue = true; 134 else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) || 135 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) || 136 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) || 137 (net->broadcom_cap_exist)) 138 retValue = true; 139 else if (net->bssht.bd_rt2rt_aggregation) 140 retValue = true; 141 else 142 retValue = false; 143 144 return retValue; 145} 146 147static void ht_iot_peer_determine(struct rtllib_device *ieee) 148{ 149 struct rt_hi_throughput *ht_info = ieee->ht_info; 150 struct rtllib_network *net = &ieee->current_network; 151 152 if (net->bssht.bd_rt2rt_aggregation) { 153 ht_info->iot_peer = HT_IOT_PEER_REALTEK; 154 if (net->bssht.rt2rt_ht_mode & RT_HT_CAP_USE_92SE) 155 ht_info->iot_peer = HT_IOT_PEER_REALTEK_92SE; 156 if (net->bssht.rt2rt_ht_mode & RT_HT_CAP_USE_SOFTAP) 157 ht_info->iot_peer = HT_IOT_PEER_92U_SOFTAP; 158 } else if (net->broadcom_cap_exist) { 159 ht_info->iot_peer = HT_IOT_PEER_BROADCOM; 160 } else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) || 161 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) || 162 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)) { 163 ht_info->iot_peer = HT_IOT_PEER_BROADCOM; 164 } else if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) || 165 (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) || 166 (memcmp(net->bssid, PCI_RALINK, 3) == 0) || 167 (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) || 168 (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) || 169 net->ralink_cap_exist) { 170 ht_info->iot_peer = HT_IOT_PEER_RALINK; 171 } else if ((net->atheros_cap_exist) || 172 (memcmp(net->bssid, DLINK_ATHEROS_1, 3) == 0) || 173 (memcmp(net->bssid, DLINK_ATHEROS_2, 3) == 0)) { 174 ht_info->iot_peer = HT_IOT_PEER_ATHEROS; 175 } else if ((memcmp(net->bssid, CISCO_BROADCOM, 3) == 0) || 176 net->cisco_cap_exist) { 177 ht_info->iot_peer = HT_IOT_PEER_CISCO; 178 } else if ((memcmp(net->bssid, LINKSYS_MARVELL_4400N, 3) == 0) || 179 net->marvell_cap_exist) { 180 ht_info->iot_peer = HT_IOT_PEER_MARVELL; 181 } else if (net->airgo_cap_exist) { 182 ht_info->iot_peer = HT_IOT_PEER_AIRGO; 183 } else { 184 ht_info->iot_peer = HT_IOT_PEER_UNKNOWN; 185 } 186 187 netdev_dbg(ieee->dev, "IOTPEER: %x\n", ht_info->iot_peer); 188} 189 190static u8 ht_iot_act_is_mgnt_use_cck_6m(struct rtllib_device *ieee, 191 struct rtllib_network *network) 192{ 193 u8 retValue = 0; 194 195 if (ieee->ht_info->iot_peer == HT_IOT_PEER_BROADCOM) 196 retValue = 1; 197 198 return retValue; 199} 200 201static u8 ht_iot_act_is_ccd_fsync(struct rtllib_device *ieee) 202{ 203 u8 retValue = 0; 204 205 if (ieee->ht_info->iot_peer == HT_IOT_PEER_BROADCOM) 206 retValue = 1; 207 return retValue; 208} 209 210static void ht_iot_act_determine_ra_func(struct rtllib_device *ieee, bool bPeerRx2ss) 211{ 212 struct rt_hi_throughput *ht_info = ieee->ht_info; 213 214 ht_info->iot_ra_func &= HT_IOT_RAFUNC_DISABLE_ALL; 215 216 if (ht_info->iot_peer == HT_IOT_PEER_RALINK && !bPeerRx2ss) 217 ht_info->iot_ra_func |= HT_IOT_RAFUNC_PEER_1R; 218 219 if (ht_info->iot_action & HT_IOT_ACT_AMSDU_ENABLE) 220 ht_info->iot_ra_func |= HT_IOT_RAFUNC_TX_AMSDU; 221} 222 223void ht_reset_iot_setting(struct rt_hi_throughput *ht_info) 224{ 225 ht_info->iot_action = 0; 226 ht_info->iot_peer = HT_IOT_PEER_UNKNOWN; 227 ht_info->iot_ra_func = 0; 228} 229 230void ht_construct_capability_element(struct rtllib_device *ieee, u8 *pos_ht_cap, 231 u8 *len, u8 is_encrypt, bool assoc) 232{ 233 struct rt_hi_throughput *ht = ieee->ht_info; 234 struct ht_capab_ele *cap_ele = NULL; 235 236 if (!pos_ht_cap || !ht) { 237 netdev_warn(ieee->dev, 238 "%s(): posHTCap and ht_info are null\n", __func__); 239 return; 240 } 241 memset(pos_ht_cap, 0, *len); 242 243 if ((assoc) && (ht->peer_ht_spec_ver == HT_SPEC_VER_EWC)) { 244 static const u8 EWC11NHTCap[] = { 0x00, 0x90, 0x4c, 0x33 }; 245 246 memcpy(pos_ht_cap, EWC11NHTCap, sizeof(EWC11NHTCap)); 247 cap_ele = (struct ht_capab_ele *)&pos_ht_cap[4]; 248 *len = 30 + 2; 249 } else { 250 cap_ele = (struct ht_capab_ele *)pos_ht_cap; 251 *len = 26 + 2; 252 } 253 254 cap_ele->AdvCoding = 0; 255 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) 256 cap_ele->ChlWidth = 0; 257 else 258 cap_ele->ChlWidth = 1; 259 260 cap_ele->MimoPwrSave = 3; 261 cap_ele->GreenField = 0; 262 cap_ele->ShortGI20Mhz = 1; 263 cap_ele->ShortGI40Mhz = 1; 264 265 cap_ele->TxSTBC = 1; 266 cap_ele->RxSTBC = 0; 267 cap_ele->DelayBA = 0; 268 cap_ele->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0; 269 cap_ele->DssCCk = 1; 270 cap_ele->PSMP = 0; 271 cap_ele->LSigTxopProtect = 0; 272 273 netdev_dbg(ieee->dev, 274 "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", 275 cap_ele->ChlWidth, cap_ele->MaxAMSDUSize, cap_ele->DssCCk); 276 277 if (is_encrypt) { 278 cap_ele->MPDUDensity = 7; 279 cap_ele->MaxRxAMPDUFactor = 2; 280 } else { 281 cap_ele->MaxRxAMPDUFactor = 3; 282 cap_ele->MPDUDensity = 0; 283 } 284 285 memcpy(cap_ele->MCS, ieee->reg_dot11ht_oper_rate_set, 16); 286 memset(&cap_ele->ExtHTCapInfo, 0, 2); 287 memset(cap_ele->TxBFCap, 0, 4); 288 289 cap_ele->ASCap = 0; 290 291 if (assoc) { 292 if (ht->iot_action & HT_IOT_ACT_DISABLE_MCS15) 293 cap_ele->MCS[1] &= 0x7f; 294 295 if (ht->iot_action & HT_IOT_ACT_DISABLE_MCS14) 296 cap_ele->MCS[1] &= 0xbf; 297 298 if (ht->iot_action & HT_IOT_ACT_DISABLE_ALL_2SS) 299 cap_ele->MCS[1] &= 0x00; 300 301 if (ht->iot_action & HT_IOT_ACT_DISABLE_RX_40MHZ_SHORT_GI) 302 cap_ele->ShortGI40Mhz = 0; 303 304 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) { 305 cap_ele->ChlWidth = 0; 306 cap_ele->MCS[1] = 0; 307 } 308 } 309} 310 311void ht_construct_rt2rt_agg_element(struct rtllib_device *ieee, u8 *posRT2RTAgg, 312 u8 *len) 313{ 314 if (!posRT2RTAgg) { 315 netdev_warn(ieee->dev, "%s(): posRT2RTAgg is null\n", __func__); 316 return; 317 } 318 memset(posRT2RTAgg, 0, *len); 319 *posRT2RTAgg++ = 0x00; 320 *posRT2RTAgg++ = 0xe0; 321 *posRT2RTAgg++ = 0x4c; 322 *posRT2RTAgg++ = 0x02; 323 *posRT2RTAgg++ = 0x01; 324 325 *posRT2RTAgg = 0x30; 326 327 if (ieee->bSupportRemoteWakeUp) 328 *posRT2RTAgg |= RT_HT_CAP_USE_WOW; 329 330 *len = 6 + 2; 331} 332 333static u8 ht_pick_mcs_rate(struct rtllib_device *ieee, u8 *pOperateMCS) 334{ 335 u8 i; 336 337 if (!pOperateMCS) { 338 netdev_warn(ieee->dev, "%s(): pOperateMCS is null\n", __func__); 339 return false; 340 } 341 342 switch (ieee->mode) { 343 case WIRELESS_MODE_B: 344 case WIRELESS_MODE_G: 345 for (i = 0; i <= 15; i++) 346 pOperateMCS[i] = 0; 347 break; 348 case WIRELESS_MODE_N_24G: 349 pOperateMCS[0] &= RATE_ADPT_1SS_MASK; 350 pOperateMCS[1] &= RATE_ADPT_2SS_MASK; 351 pOperateMCS[3] &= RATE_ADPT_MCS32_MASK; 352 break; 353 default: 354 break; 355 } 356 357 return true; 358} 359 360u8 ht_get_highest_mcs_rate(struct rtllib_device *ieee, u8 *pMCSRateSet, 361 u8 *pMCSFilter) 362{ 363 u8 i, j; 364 u8 bitMap; 365 u8 mcsRate = 0; 366 u8 availableMcsRate[16]; 367 368 if (!pMCSRateSet || !pMCSFilter) { 369 netdev_warn(ieee->dev, 370 "%s(): pMCSRateSet and pMCSFilter are null\n", 371 __func__); 372 return false; 373 } 374 for (i = 0; i < 16; i++) 375 availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i]; 376 377 for (i = 0; i < 16; i++) { 378 if (availableMcsRate[i] != 0) 379 break; 380 } 381 if (i == 16) 382 return false; 383 384 for (i = 0; i < 16; i++) { 385 if (availableMcsRate[i] != 0) { 386 bitMap = availableMcsRate[i]; 387 for (j = 0; j < 8; j++) { 388 if ((bitMap % 2) != 0) { 389 if (ht_mcs_to_data_rate(ieee, (8 * i + j)) > 390 ht_mcs_to_data_rate(ieee, mcsRate)) 391 mcsRate = 8 * i + j; 392 } 393 bitMap >>= 1; 394 } 395 } 396 } 397 return mcsRate | 0x80; 398} 399 400static u8 ht_filter_mcs_rate(struct rtllib_device *ieee, u8 *pSupportMCS, 401 u8 *pOperateMCS) 402{ 403 u8 i; 404 405 for (i = 0; i <= 15; i++) 406 pOperateMCS[i] = ieee->reg_dot11tx_ht_oper_rate_set[i] & 407 pSupportMCS[i]; 408 409 ht_pick_mcs_rate(ieee, pOperateMCS); 410 411 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) 412 pOperateMCS[1] = 0; 413 414 for (i = 2; i <= 15; i++) 415 pOperateMCS[i] = 0; 416 417 return true; 418} 419 420void ht_set_connect_bw_mode(struct rtllib_device *ieee, 421 enum ht_channel_width bandwidth, 422 enum ht_extchnl_offset Offset); 423 424void ht_on_assoc_rsp(struct rtllib_device *ieee) 425{ 426 struct rt_hi_throughput *ht_info = ieee->ht_info; 427 struct ht_capab_ele *pPeerHTCap = NULL; 428 struct ht_info_ele *pPeerHTInfo = NULL; 429 u8 *pMcsFilter = NULL; 430 431 static const u8 EWC11NHTCap[] = { 0x00, 0x90, 0x4c, 0x33 }; 432 static const u8 EWC11NHTInfo[] = { 0x00, 0x90, 0x4c, 0x34 }; 433 434 if (!ht_info->current_ht_support) { 435 netdev_warn(ieee->dev, "%s(): HT_DISABLE\n", __func__); 436 return; 437 } 438 netdev_dbg(ieee->dev, "%s(): HT_ENABLE\n", __func__); 439 440 if (!memcmp(ht_info->peer_ht_cap_buf, EWC11NHTCap, sizeof(EWC11NHTCap))) 441 pPeerHTCap = (struct ht_capab_ele *)(&ht_info->peer_ht_cap_buf[4]); 442 else 443 pPeerHTCap = (struct ht_capab_ele *)(ht_info->peer_ht_cap_buf); 444 445 if (!memcmp(ht_info->peer_ht_info_buf, EWC11NHTInfo, sizeof(EWC11NHTInfo))) 446 pPeerHTInfo = (struct ht_info_ele *) 447 (&ht_info->peer_ht_info_buf[4]); 448 else 449 pPeerHTInfo = (struct ht_info_ele *)(ht_info->peer_ht_info_buf); 450 451#ifdef VERBOSE_DEBUG 452 print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE, 453 pPeerHTCap, sizeof(struct ht_capab_ele)); 454#endif 455 ht_set_connect_bw_mode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth), 456 (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset)); 457 ht_info->cur_tx_bw40mhz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ? 458 true : false); 459 460 ht_info->cur_short_gi_20mhz = ((pPeerHTCap->ShortGI20Mhz == 1) ? true : false); 461 ht_info->cur_short_gi_40mhz = ((pPeerHTCap->ShortGI40Mhz == 1) ? true : false); 462 463 ht_info->current_ampdu_enable = ht_info->ampdu_enable; 464 if (ieee->rtllib_ap_sec_type && 465 (ieee->rtllib_ap_sec_type(ieee) & (SEC_ALG_WEP | SEC_ALG_TKIP))) { 466 if ((ht_info->iot_peer == HT_IOT_PEER_ATHEROS) || 467 (ht_info->iot_peer == HT_IOT_PEER_UNKNOWN)) 468 ht_info->current_ampdu_enable = false; 469 } 470 471 if (ieee->current_network.bssht.bd_rt2rt_aggregation) { 472 if (ieee->pairwise_key_type != KEY_TYPE_NA) 473 ht_info->CurrentAMPDUFactor = 474 pPeerHTCap->MaxRxAMPDUFactor; 475 else 476 ht_info->CurrentAMPDUFactor = HT_AGG_SIZE_64K; 477 } else { 478 ht_info->CurrentAMPDUFactor = min_t(u32, pPeerHTCap->MaxRxAMPDUFactor, 479 HT_AGG_SIZE_32K); 480 } 481 482 ht_info->current_mpdu_density = pPeerHTCap->MPDUDensity; 483 if (ht_info->iot_action & HT_IOT_ACT_TX_USE_AMSDU_8K) 484 ht_info->current_ampdu_enable = false; 485 486 ht_info->cur_rx_reorder_enable = 1; 487 488 if (pPeerHTCap->MCS[0] == 0) 489 pPeerHTCap->MCS[0] = 0xff; 490 491 ht_iot_act_determine_ra_func(ieee, ((pPeerHTCap->MCS[1]) != 0)); 492 493 ht_filter_mcs_rate(ieee, pPeerHTCap->MCS, ieee->dot11ht_oper_rate_set); 494 495 pMcsFilter = MCS_FILTER_ALL; 496 ieee->HTHighestOperaRate = ht_get_highest_mcs_rate(ieee, 497 ieee->dot11ht_oper_rate_set, 498 pMcsFilter); 499 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate; 500 501 ht_info->current_op_mode = pPeerHTInfo->OptMode; 502} 503 504void ht_initialize_ht_info(struct rtllib_device *ieee) 505{ 506 struct rt_hi_throughput *ht_info = ieee->ht_info; 507 508 ht_info->current_ht_support = false; 509 510 ht_info->cur_bw_40mhz = false; 511 ht_info->cur_tx_bw40mhz = false; 512 513 ht_info->cur_short_gi_20mhz = false; 514 ht_info->cur_short_gi_40mhz = false; 515 516 ht_info->current_mpdu_density = 0; 517 ht_info->CurrentAMPDUFactor = ht_info->ampdu_factor; 518 519 memset((void *)(&ht_info->self_ht_cap), 0, 520 sizeof(ht_info->self_ht_cap)); 521 memset((void *)(&ht_info->peer_ht_cap_buf), 0, 522 sizeof(ht_info->peer_ht_cap_buf)); 523 memset((void *)(&ht_info->peer_ht_info_buf), 0, 524 sizeof(ht_info->peer_ht_info_buf)); 525 526 ht_info->sw_bw_in_progress = false; 527 528 ht_info->peer_ht_spec_ver = HT_SPEC_VER_IEEE; 529 530 ht_info->current_rt2rt_aggregation = false; 531 ht_info->current_rt2rt_long_slot_time = false; 532 533 ht_info->iot_peer = 0; 534 ht_info->iot_action = 0; 535 ht_info->iot_ra_func = 0; 536 537 { 538 u8 *RegHTSuppRateSets = &ieee->reg_ht_supp_rate_set[0]; 539 540 RegHTSuppRateSets[0] = 0xFF; 541 RegHTSuppRateSets[1] = 0xFF; 542 RegHTSuppRateSets[4] = 0x01; 543 } 544} 545 546void ht_initialize_bss_desc(struct bss_ht *pBssHT) 547{ 548 pBssHT->bd_support_ht = false; 549 memset(pBssHT->bd_ht_cap_buf, 0, sizeof(pBssHT->bd_ht_cap_buf)); 550 pBssHT->bd_ht_cap_len = 0; 551 memset(pBssHT->bd_ht_info_buf, 0, sizeof(pBssHT->bd_ht_info_buf)); 552 pBssHT->bd_ht_info_len = 0; 553 554 pBssHT->bd_ht_spec_ver = HT_SPEC_VER_IEEE; 555 556 pBssHT->bd_rt2rt_aggregation = false; 557 pBssHT->bd_rt2rt_long_slot_time = false; 558 pBssHT->rt2rt_ht_mode = (enum rt_ht_capability)0; 559} 560 561void ht_reset_self_and_save_peer_setting(struct rtllib_device *ieee, 562 struct rtllib_network *pNetwork) 563{ 564 struct rt_hi_throughput *ht_info = ieee->ht_info; 565 u8 bIOTAction = 0; 566 567 /* unmark enable_ht flag here is the same reason why unmarked in 568 * function rtllib_softmac_new_net. WB 2008.09.10 569 */ 570 if (pNetwork->bssht.bd_support_ht) { 571 ht_info->current_ht_support = true; 572 ht_info->peer_ht_spec_ver = pNetwork->bssht.bd_ht_spec_ver; 573 574 if (pNetwork->bssht.bd_ht_cap_len > 0 && 575 pNetwork->bssht.bd_ht_cap_len <= sizeof(ht_info->peer_ht_cap_buf)) 576 memcpy(ht_info->peer_ht_cap_buf, 577 pNetwork->bssht.bd_ht_cap_buf, 578 pNetwork->bssht.bd_ht_cap_len); 579 580 if (pNetwork->bssht.bd_ht_info_len > 0 && 581 pNetwork->bssht.bd_ht_info_len <= 582 sizeof(ht_info->peer_ht_info_buf)) 583 memcpy(ht_info->peer_ht_info_buf, 584 pNetwork->bssht.bd_ht_info_buf, 585 pNetwork->bssht.bd_ht_info_len); 586 587 ht_info->current_rt2rt_aggregation = 588 pNetwork->bssht.bd_rt2rt_aggregation; 589 ht_info->current_rt2rt_long_slot_time = 590 pNetwork->bssht.bd_rt2rt_long_slot_time; 591 592 ht_iot_peer_determine(ieee); 593 594 ht_info->iot_action = 0; 595 bIOTAction = ht_iot_act_is_mgnt_use_cck_6m(ieee, pNetwork); 596 if (bIOTAction) 597 ht_info->iot_action |= HT_IOT_ACT_MGNT_USE_CCK_6M; 598 bIOTAction = ht_iot_act_is_ccd_fsync(ieee); 599 if (bIOTAction) 600 ht_info->iot_action |= HT_IOT_ACT_CDD_FSYNC; 601 } else { 602 ht_info->current_ht_support = false; 603 ht_info->current_rt2rt_aggregation = false; 604 ht_info->current_rt2rt_long_slot_time = false; 605 606 ht_info->iot_action = 0; 607 ht_info->iot_ra_func = 0; 608 } 609} 610 611void HT_update_self_and_peer_setting(struct rtllib_device *ieee, 612 struct rtllib_network *pNetwork) 613{ 614 struct rt_hi_throughput *ht_info = ieee->ht_info; 615 struct ht_info_ele *pPeerHTInfo = 616 (struct ht_info_ele *)pNetwork->bssht.bd_ht_info_buf; 617 618 if (ht_info->current_ht_support) { 619 if (pNetwork->bssht.bd_ht_info_len != 0) 620 ht_info->current_op_mode = pPeerHTInfo->OptMode; 621 } 622} 623EXPORT_SYMBOL(HT_update_self_and_peer_setting); 624 625u8 ht_c_check(struct rtllib_device *ieee, u8 *pFrame) 626{ 627 if (ieee->ht_info->current_ht_support) { 628 if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) { 629 netdev_dbg(ieee->dev, "HT CONTROL FILED EXIST!!\n"); 630 return true; 631 } 632 } 633 return false; 634} 635 636static void ht_set_connect_bw_mode_callback(struct rtllib_device *ieee) 637{ 638 struct rt_hi_throughput *ht_info = ieee->ht_info; 639 640 if (ht_info->cur_bw_40mhz) { 641 if (ht_info->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER) 642 ieee->set_chan(ieee->dev, 643 ieee->current_network.channel + 2); 644 else if (ht_info->CurSTAExtChnlOffset == 645 HT_EXTCHNL_OFFSET_LOWER) 646 ieee->set_chan(ieee->dev, 647 ieee->current_network.channel - 2); 648 else 649 ieee->set_chan(ieee->dev, 650 ieee->current_network.channel); 651 652 ieee->set_bw_mode_handler(ieee->dev, HT_CHANNEL_WIDTH_20_40, 653 ht_info->CurSTAExtChnlOffset); 654 } else { 655 ieee->set_chan(ieee->dev, ieee->current_network.channel); 656 ieee->set_bw_mode_handler(ieee->dev, HT_CHANNEL_WIDTH_20, 657 HT_EXTCHNL_OFFSET_NO_EXT); 658 } 659 660 ht_info->sw_bw_in_progress = false; 661} 662 663void ht_set_connect_bw_mode(struct rtllib_device *ieee, 664 enum ht_channel_width bandwidth, 665 enum ht_extchnl_offset Offset) 666{ 667 struct rt_hi_throughput *ht_info = ieee->ht_info; 668 669 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) 670 bandwidth = HT_CHANNEL_WIDTH_20; 671 672 if (ht_info->sw_bw_in_progress) { 673 pr_info("%s: sw_bw_in_progress!!\n", __func__); 674 return; 675 } 676 if (bandwidth == HT_CHANNEL_WIDTH_20_40) { 677 if (ieee->current_network.channel < 2 && 678 Offset == HT_EXTCHNL_OFFSET_LOWER) 679 Offset = HT_EXTCHNL_OFFSET_NO_EXT; 680 if (Offset == HT_EXTCHNL_OFFSET_UPPER || 681 Offset == HT_EXTCHNL_OFFSET_LOWER) { 682 ht_info->cur_bw_40mhz = true; 683 ht_info->CurSTAExtChnlOffset = Offset; 684 } else { 685 ht_info->cur_bw_40mhz = false; 686 ht_info->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; 687 } 688 } else { 689 ht_info->cur_bw_40mhz = false; 690 ht_info->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; 691 } 692 693 netdev_dbg(ieee->dev, "%s():ht_info->bCurBW40MHz:%x\n", __func__, 694 ht_info->cur_bw_40mhz); 695 696 ht_info->sw_bw_in_progress = true; 697 698 ht_set_connect_bw_mode_callback(ieee); 699} 700