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
ht_update_default_setting(struct rtllib_device * ieee)70 void 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
ht_mcs_to_data_rate(struct rtllib_device * ieee,u8 mcs_rate)86 static 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
tx_count_to_data_rate(struct rtllib_device * ieee,u8 data_rate)97 u16 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
is_ht_half_nmode_aps(struct rtllib_device * ieee)122 bool 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
ht_iot_peer_determine(struct rtllib_device * ieee)147 static 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
ht_iot_act_is_mgnt_use_cck_6m(struct rtllib_device * ieee,struct rtllib_network * network)190 static 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
ht_iot_act_is_ccd_fsync(struct rtllib_device * ieee)201 static 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
ht_iot_act_determine_ra_func(struct rtllib_device * ieee,bool bPeerRx2ss)210 static 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
ht_reset_iot_setting(struct rt_hi_throughput * ht_info)223 void 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
ht_construct_capability_element(struct rtllib_device * ieee,u8 * pos_ht_cap,u8 * len,u8 is_encrypt,bool assoc)230 void 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(): pos_ht_cap 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->adv_coding = 0;
255 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev))
256 cap_ele->chl_width = 0;
257 else
258 cap_ele->chl_width = 1;
259
260 cap_ele->mimo_pwr_save = 3;
261 cap_ele->green_field = 0;
262 cap_ele->short_gi_20mhz = 1;
263 cap_ele->short_gi_40mhz = 1;
264
265 cap_ele->tx_stbc = 1;
266 cap_ele->rx_stbc = 0;
267 cap_ele->delay_ba = 0;
268 cap_ele->max_amsdu_size = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0;
269 cap_ele->dss_cck = 1;
270 cap_ele->PSMP = 0;
271 cap_ele->lsig_txop_protect = 0;
272
273 netdev_dbg(ieee->dev,
274 "TX HT cap/info ele BW=%d max_amsdu_size:%d dss_cck:%d\n",
275 cap_ele->chl_width, cap_ele->max_amsdu_size, cap_ele->dss_cck);
276
277 if (is_encrypt) {
278 cap_ele->mpdu_density = 7;
279 cap_ele->max_rx_ampdu_factor = 2;
280 } else {
281 cap_ele->max_rx_ampdu_factor = 3;
282 cap_ele->mpdu_density = 0;
283 }
284
285 memcpy(cap_ele->MCS, ieee->reg_dot11ht_oper_rate_set, 16);
286 memset(&cap_ele->ext_ht_cap_info, 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->short_gi_40mhz = 0;
303
304 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) {
305 cap_ele->chl_width = 0;
306 cap_ele->MCS[1] = 0;
307 }
308 }
309 }
310
ht_construct_rt2rt_agg_element(struct rtllib_device * ieee,u8 * posRT2RTAgg,u8 * len)311 void 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
ht_pick_mcs_rate(struct rtllib_device * ieee,u8 * pOperateMCS)333 static 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
ht_get_highest_mcs_rate(struct rtllib_device * ieee,u8 * pMCSRateSet,u8 * pMCSFilter)360 u8 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
ht_filter_mcs_rate(struct rtllib_device * ieee,u8 * pSupportMCS,u8 * pOperateMCS)400 static 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
420 void ht_set_connect_bw_mode(struct rtllib_device *ieee,
421 enum ht_channel_width bandwidth,
422 enum ht_extchnl_offset Offset);
423
ht_on_assoc_rsp(struct rtllib_device * ieee)424 void 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->chl_width),
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->short_gi_20mhz == 1) ? true : false);
461 ht_info->cur_short_gi_40mhz = ((pPeerHTCap->short_gi_40mhz == 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->current_ampdu_factor =
474 pPeerHTCap->max_rx_ampdu_factor;
475 else
476 ht_info->current_ampdu_factor = HT_AGG_SIZE_64K;
477 } else {
478 ht_info->current_ampdu_factor = min_t(u32, pPeerHTCap->max_rx_ampdu_factor,
479 HT_AGG_SIZE_32K);
480 }
481
482 ht_info->current_mpdu_density = pPeerHTCap->mpdu_density;
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->ht_curr_op_rate = ieee->HTHighestOperaRate;
500
501 ht_info->current_op_mode = pPeerHTInfo->opt_mode;
502 }
503
ht_initialize_ht_info(struct rtllib_device * ieee)504 void 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->current_ampdu_factor = 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
ht_initialize_bss_desc(struct bss_ht * bss_ht)546 void ht_initialize_bss_desc(struct bss_ht *bss_ht)
547 {
548 bss_ht->bd_support_ht = false;
549 memset(bss_ht->bd_ht_cap_buf, 0, sizeof(bss_ht->bd_ht_cap_buf));
550 bss_ht->bd_ht_cap_len = 0;
551 memset(bss_ht->bd_ht_info_buf, 0, sizeof(bss_ht->bd_ht_info_buf));
552 bss_ht->bd_ht_info_len = 0;
553
554 bss_ht->bd_ht_spec_ver = HT_SPEC_VER_IEEE;
555
556 bss_ht->bd_rt2rt_aggregation = false;
557 bss_ht->bd_rt2rt_long_slot_time = false;
558 bss_ht->rt2rt_ht_mode = (enum rt_ht_capability)0;
559 }
560
ht_reset_self_and_save_peer_setting(struct rtllib_device * ieee,struct rtllib_network * network)561 void ht_reset_self_and_save_peer_setting(struct rtllib_device *ieee,
562 struct rtllib_network *network)
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 (network->bssht.bd_support_ht) {
571 ht_info->current_ht_support = true;
572 ht_info->peer_ht_spec_ver = network->bssht.bd_ht_spec_ver;
573
574 if (network->bssht.bd_ht_cap_len > 0 &&
575 network->bssht.bd_ht_cap_len <= sizeof(ht_info->peer_ht_cap_buf))
576 memcpy(ht_info->peer_ht_cap_buf,
577 network->bssht.bd_ht_cap_buf,
578 network->bssht.bd_ht_cap_len);
579
580 if (network->bssht.bd_ht_info_len > 0 &&
581 network->bssht.bd_ht_info_len <=
582 sizeof(ht_info->peer_ht_info_buf))
583 memcpy(ht_info->peer_ht_info_buf,
584 network->bssht.bd_ht_info_buf,
585 network->bssht.bd_ht_info_len);
586
587 ht_info->current_rt2rt_aggregation =
588 network->bssht.bd_rt2rt_aggregation;
589 ht_info->current_rt2rt_long_slot_time =
590 network->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, network);
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
HT_update_self_and_peer_setting(struct rtllib_device * ieee,struct rtllib_network * network)611 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
612 struct rtllib_network *network)
613 {
614 struct rt_hi_throughput *ht_info = ieee->ht_info;
615 struct ht_info_ele *pPeerHTInfo =
616 (struct ht_info_ele *)network->bssht.bd_ht_info_buf;
617
618 if (ht_info->current_ht_support) {
619 if (network->bssht.bd_ht_info_len != 0)
620 ht_info->current_op_mode = pPeerHTInfo->opt_mode;
621 }
622 }
623 EXPORT_SYMBOL(HT_update_self_and_peer_setting);
624
ht_c_check(struct rtllib_device * ieee,u8 * frame)625 u8 ht_c_check(struct rtllib_device *ieee, u8 *frame)
626 {
627 if (ieee->ht_info->current_ht_support) {
628 if ((is_qos_data_frame(frame) && frame_order(frame)) == 1) {
629 netdev_dbg(ieee->dev, "HT CONTROL FILED EXIST!!\n");
630 return true;
631 }
632 }
633 return false;
634 }
635
ht_set_connect_bw_mode_callback(struct rtllib_device * ieee)636 static 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->cur_sta_ext_chnl_offset == HT_EXTCHNL_OFFSET_UPPER)
642 ieee->set_chan(ieee->dev,
643 ieee->current_network.channel + 2);
644 else if (ht_info->cur_sta_ext_chnl_offset ==
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->cur_sta_ext_chnl_offset);
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
ht_set_connect_bw_mode(struct rtllib_device * ieee,enum ht_channel_width bandwidth,enum ht_extchnl_offset Offset)663 void 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->cur_sta_ext_chnl_offset = Offset;
684 } else {
685 ht_info->cur_bw_40mhz = false;
686 ht_info->cur_sta_ext_chnl_offset = HT_EXTCHNL_OFFSET_NO_EXT;
687 }
688 } else {
689 ht_info->cur_bw_40mhz = false;
690 ht_info->cur_sta_ext_chnl_offset = 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