1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <drv_types.h>
25 u8 center_ch_2g[CENTER_CH_2G_NUM] = {
34 u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM] = {
46 u8 op_chs_of_cch_2g_40m[CENTER_CH_2G_40M_NUM][2] = {
58 u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM] = {
66 /* G04 */100, 102, 104,
68 /* G05 */108, 110, 112,
70 /* G06 */116, 118, 120,
72 /* G07 */124, 126, 128,
73 /* G08 */132, 134, 136,
75 /* G09 */140, 142, 144,
76 /* G10 */149, 151, 153,
78 /* G11 */157, 159, 161,
80 /* G12 */165, 167, 169,
82 /* G13 */173, 175, 177
85 u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM] = {
102 u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM] = {
119 u8 op_chs_of_cch_5g_40m[CENTER_CH_5G_40M_NUM][2] = {
124 {100, 104}, /* 102 */
125 {108, 112}, /* 110 */
126 {116, 120}, /* 118 */
127 {124, 128}, /* 126 */
128 {132, 136}, /* 134 */
129 {140, 144}, /* 142 */
130 {149, 153}, /* 151 */
131 {157, 161}, /* 159 */
132 {165, 169}, /* 167 */
133 {173, 177}, /* 175 */
136 u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM] = {
146 u8 op_chs_of_cch_5g_80m[CENTER_CH_5G_80M_NUM][4] = {
147 {36, 40, 44, 48}, /* 42 */
148 {52, 56, 60, 64}, /* 58 */
149 {100, 104, 108, 112}, /* 106 */
150 {116, 120, 124, 128}, /* 122 */
151 {132, 136, 140, 144}, /* 138 */
152 {149, 153, 157, 161}, /* 155 */
153 {165, 169, 173, 177}, /* 171 */
156 u8 center_ch_5g_160m[CENTER_CH_5G_160M_NUM] = {
162 u8 op_chs_of_cch_5g_160m[CENTER_CH_5G_160M_NUM][8] = {
163 {36, 40, 44, 48, 52, 56, 60, 64}, /* 50 */
164 {100, 104, 108, 112, 116, 120, 124, 128}, /* 114 */
165 {149, 153, 157, 161, 165, 169, 173, 177}, /* 163 */
168 struct center_chs_ent_t {
173 struct center_chs_ent_t center_chs_2g_by_bw[] = {
174 {CENTER_CH_2G_NUM, center_ch_2g},
175 {CENTER_CH_2G_40M_NUM, center_ch_2g_40m},
178 struct center_chs_ent_t center_chs_5g_by_bw[] = {
179 {CENTER_CH_5G_20M_NUM, center_ch_5g_20m},
180 {CENTER_CH_5G_40M_NUM, center_ch_5g_40m},
181 {CENTER_CH_5G_80M_NUM, center_ch_5g_80m},
182 {CENTER_CH_5G_160M_NUM, center_ch_5g_160m},
185 struct op_chs_ent_t {
190 struct op_chs_ent_t op_chs_of_cch_2g_by_bw[] = {
192 {2, (u8 *)op_chs_of_cch_2g_40m},
195 struct op_chs_ent_t op_chs_of_cch_5g_by_bw[] = {
196 {1, center_ch_5g_20m},
197 {2, (u8 *)op_chs_of_cch_5g_40m},
198 {4, (u8 *)op_chs_of_cch_5g_80m},
199 {8, (u8 *)op_chs_of_cch_5g_160m},
202 inline u8 center_chs_5g_num(u8 bw)
204 if (bw >= CHANNEL_WIDTH_160)
207 return center_chs_5g_by_bw[bw].ch_num;
210 inline u8 center_chs_5g(u8 bw, u8 id)
212 if (bw >= CHANNEL_WIDTH_160)
215 if (id >= center_chs_5g_num(bw))
218 return center_chs_5g_by_bw[bw].chs[id];
222 * Get available op channels by @param cch, @param bw
223 * @cch: the given center channel
224 * @bw: the given bandwidth
225 * @op_chs: the pointer to return pointer of op channel array
226 * @op_ch_num: the pointer to return pointer of op channel number
228 * return valid (1) or not (0)
230 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num)
233 struct center_chs_ent_t *c_chs_ent = NULL;
234 struct op_chs_ent_t *op_chs_ent = NULL;
238 && bw >= CHANNEL_WIDTH_20 && bw <= CHANNEL_WIDTH_40
240 c_chs_ent = ¢er_chs_2g_by_bw[bw];
241 op_chs_ent = &op_chs_of_cch_2g_by_bw[bw];
242 } else if (cch >= 36 && cch <= 177
243 && bw >= CHANNEL_WIDTH_20 && bw <= CHANNEL_WIDTH_160
245 c_chs_ent = ¢er_chs_5g_by_bw[bw];
246 op_chs_ent = &op_chs_of_cch_5g_by_bw[bw];
252 for (i = 0; i < c_chs_ent->ch_num; i++)
253 if (cch == *(c_chs_ent->chs + i))
256 if (i == c_chs_ent->ch_num) {
261 *op_chs = op_chs_ent->chs + op_chs_ent->ch_num * i;
262 *op_ch_num = op_chs_ent->ch_num;
268 int rtw_ch2freq(int chan)
270 /* see 802.11 17.3.8.3.2 and Annex J
271 * there are overlapping channel numbers in 5GHz and 2GHz bands */
274 * RTK: don't consider the overlapping channel numbers: 5G channel <= 14,
275 * because we don't support it. simply judge from channel number
278 if (chan >= 1 && chan <= 14) {
282 return 2407 + chan * 5;
283 } else if (chan >= 36 && chan <= 177)
284 return 5000 + chan * 5;
286 return 0; /* not supported */
289 int rtw_freq2ch(int freq)
291 /* see 802.11 17.3.8.3.2 and Annex J */
294 else if (freq < 2484)
295 return (freq - 2407) / 5;
296 else if (freq >= 4910 && freq <= 4980)
297 return (freq - 4000) / 5;
298 else if (freq <= 45000) /* DMG band lower limit */
299 return (freq - 5000) / 5;
300 else if (freq >= 58320 && freq <= 64800)
301 return (freq - 56160) / 2160;
306 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo)
310 u32 hi_ret = 0, lo_ret = 0;
319 c_ch = rtw_get_center_ch(ch, bw, offset);
320 freq = rtw_ch2freq(c_ch);
327 if (bw == CHANNEL_WIDTH_80) {
330 } else if (bw == CHANNEL_WIDTH_40) {
333 } else if (bw == CHANNEL_WIDTH_20) {
350 const char *const _ch_width_str[] = {
359 const u8 _ch_width_to_bw_cap[] = {
368 const char *const _band_str[] = {
375 const u8 _band_to_band_cap[] = {
382 #ifdef CONFIG_80211AC_VHT
383 #define COUNTRY_CHPLAN_ASSIGN_EN_11AC(_val) , .en_11ac = (_val)
385 #define COUNTRY_CHPLAN_ASSIGN_EN_11AC(_val)
388 #if RTW_DEF_MODULE_REGULATORY_CERT
389 #define COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_val) , .def_module_flags = (_val)
391 #define COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_val)
394 /* has def_module_flags specified, used by common map and HAL dfference map */
395 #define COUNTRY_CHPLAN_ENT(_alpha2, _chplan, _en_11ac, _def_module_flags) \
396 {.alpha2 = (_alpha2), .chplan = (_chplan) \
397 COUNTRY_CHPLAN_ASSIGN_EN_11AC(_en_11ac) \
398 COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_def_module_flags) \
401 #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
403 #include "../platform/custom_country_chplan.h"
405 #elif RTW_DEF_MODULE_REGULATORY_CERT
407 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8821AE_HMC_M2)
408 static const struct country_chplan RTL8821AE_HMC_M2_country_chplan_map[] = {
409 COUNTRY_CHPLAN_ENT("CN", 0x51, 1, 0xFB), /* China */
410 COUNTRY_CHPLAN_ENT("RU", 0x59, 0, 0xFB), /* Russia(fac/gost), Kaliningrad */
411 COUNTRY_CHPLAN_ENT("UA", 0x26, 0, 0xFB), /* Ukraine */
413 static const u16 RTL8821AE_HMC_M2_country_chplan_map_sz = sizeof(RTL8821AE_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
416 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8821AU)
417 static const struct country_chplan RTL8821AU_country_chplan_map[] = {
418 COUNTRY_CHPLAN_ENT("RU", 0x59, 0, 0xFB), /* Russia(fac/gost), Kaliningrad */
419 COUNTRY_CHPLAN_ENT("UA", 0x26, 0, 0xFB), /* Ukraine */
421 static const u16 RTL8821AU_country_chplan_map_sz = sizeof(RTL8821AU_country_chplan_map) / sizeof(struct country_chplan);
424 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8812AENF_NGFF)
425 static const struct country_chplan RTL8812AENF_NGFF_country_chplan_map[] = {
427 static const u16 RTL8812AENF_NGFF_country_chplan_map_sz = sizeof(RTL8812AENF_NGFF_country_chplan_map) / sizeof(struct country_chplan);
430 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8812AEBT_HMC)
431 static const struct country_chplan RTL8812AEBT_HMC_country_chplan_map[] = {
433 static const u16 RTL8812AEBT_HMC_country_chplan_map_sz = sizeof(RTL8812AEBT_HMC_country_chplan_map) / sizeof(struct country_chplan);
436 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8188EE_HMC_M2)
437 static const struct country_chplan RTL8188EE_HMC_M2_country_chplan_map[] = {
439 static const u16 RTL8188EE_HMC_M2_country_chplan_map_sz = sizeof(RTL8188EE_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
442 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723BE_HMC_M2)
443 static const struct country_chplan RTL8723BE_HMC_M2_country_chplan_map[] = {
445 static const u16 RTL8723BE_HMC_M2_country_chplan_map_sz = sizeof(RTL8723BE_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
448 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723BS_NGFF1216)
449 static const struct country_chplan RTL8723BS_NGFF1216_country_chplan_map[] = {
451 static const u16 RTL8723BS_NGFF1216_country_chplan_map_sz = sizeof(RTL8723BS_NGFF1216_country_chplan_map) / sizeof(struct country_chplan);
454 #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8192EEBT_HMC_M2)
455 static const struct country_chplan RTL8192EEBT_HMC_M2_country_chplan_map[] = {
457 static const u16 RTL8192EEBT_HMC_M2_country_chplan_map_sz = sizeof(RTL8192EEBT_HMC_M2_country_chplan_map) / sizeof(struct country_chplan);
461 * rtw_def_module_get_chplan_from_country -
462 * @country_code: string of country code
464 * Return NULL for case referring to common map
466 static const struct country_chplan *rtw_def_module_get_chplan_from_country(const char *country_code)
468 const struct country_chplan *ent = NULL;
469 const struct country_chplan *hal_map = NULL;
473 /* TODO: runtime selection for multi driver */
474 #if (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8821AE_HMC_M2)
475 hal_map = RTL8821AE_HMC_M2_country_chplan_map;
476 hal_map_sz = RTL8821AE_HMC_M2_country_chplan_map_sz;
477 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8821AU)
478 hal_map = RTL8821AU_country_chplan_map;
479 hal_map_sz = RTL8821AU_country_chplan_map_sz;
480 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8812AENF_NGFF)
481 hal_map = RTL8812AENF_NGFF_country_chplan_map;
482 hal_map_sz = RTL8812AENF_NGFF_country_chplan_map_sz;
483 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8812AEBT_HMC)
484 hal_map = RTL8812AEBT_HMC_country_chplan_map;
485 hal_map_sz = RTL8812AEBT_HMC_country_chplan_map_sz;
486 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8188EE_HMC_M2)
487 hal_map = RTL8188EE_HMC_M2_country_chplan_map;
488 hal_map_sz = RTL8188EE_HMC_M2_country_chplan_map_sz;
489 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723BE_HMC_M2)
490 hal_map = RTL8723BE_HMC_M2_country_chplan_map;
491 hal_map_sz = RTL8723BE_HMC_M2_country_chplan_map_sz;
492 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723BS_NGFF1216)
493 hal_map = RTL8723BS_NGFF1216_country_chplan_map;
494 hal_map_sz = RTL8723BS_NGFF1216_country_chplan_map_sz;
495 #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8192EEBT_HMC_M2)
496 hal_map = RTL8192EEBT_HMC_M2_country_chplan_map;
497 hal_map_sz = RTL8192EEBT_HMC_M2_country_chplan_map_sz;
500 if (hal_map == NULL || hal_map_sz == 0)
503 for (i = 0; i < hal_map_sz; i++) {
504 if (strncmp(country_code, hal_map[i].alpha2, 2) == 0) {
513 #endif /* CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP or RTW_DEF_MODULE_REGULATORY_CERT */
515 static const struct country_chplan country_chplan_map[] = {
516 COUNTRY_CHPLAN_ENT("AD", 0x26, 1, 0x00), /* Andorra */
517 COUNTRY_CHPLAN_ENT("AE", 0x26, 1, 0xFB), /* United Arab Emirates */
518 COUNTRY_CHPLAN_ENT("AF", 0x42, 1, 0x00), /* Afghanistan */
519 COUNTRY_CHPLAN_ENT("AG", 0x30, 1, 0x00), /* Antigua & Barbuda */
520 COUNTRY_CHPLAN_ENT("AI", 0x26, 1, 0x00), /* Anguilla(UK) */
521 COUNTRY_CHPLAN_ENT("AL", 0x26, 1, 0xF1), /* Albania */
522 COUNTRY_CHPLAN_ENT("AM", 0x26, 1, 0xB0), /* Armenia */
523 COUNTRY_CHPLAN_ENT("AO", 0x26, 1, 0xE0), /* Angola */
524 COUNTRY_CHPLAN_ENT("AQ", 0x26, 1, 0x00), /* Antarctica */
525 COUNTRY_CHPLAN_ENT("AR", 0x57, 1, 0xF3), /* Argentina */
526 COUNTRY_CHPLAN_ENT("AS", 0x34, 1, 0x00), /* American Samoa */
527 COUNTRY_CHPLAN_ENT("AT", 0x26, 1, 0xFB), /* Austria */
528 COUNTRY_CHPLAN_ENT("AU", 0x45, 1, 0xFB), /* Australia */
529 COUNTRY_CHPLAN_ENT("AW", 0x34, 1, 0xB0), /* Aruba */
530 COUNTRY_CHPLAN_ENT("AZ", 0x26, 1, 0xF1), /* Azerbaijan */
531 COUNTRY_CHPLAN_ENT("BA", 0x26, 1, 0xF1), /* Bosnia & Herzegovina */
532 COUNTRY_CHPLAN_ENT("BB", 0x34, 1, 0x50), /* Barbados */
533 COUNTRY_CHPLAN_ENT("BD", 0x26, 1, 0xF1), /* Bangladesh */
534 COUNTRY_CHPLAN_ENT("BE", 0x26, 1, 0xFB), /* Belgium */
535 COUNTRY_CHPLAN_ENT("BF", 0x26, 1, 0xB0), /* Burkina Faso */
536 COUNTRY_CHPLAN_ENT("BG", 0x26, 1, 0xF1), /* Bulgaria */
537 COUNTRY_CHPLAN_ENT("BH", 0x47, 1, 0xF1), /* Bahrain */
538 COUNTRY_CHPLAN_ENT("BI", 0x26, 1, 0xB0), /* Burundi */
539 COUNTRY_CHPLAN_ENT("BJ", 0x26, 1, 0xB0), /* Benin */
540 COUNTRY_CHPLAN_ENT("BN", 0x47, 1, 0x10), /* Brunei */
541 COUNTRY_CHPLAN_ENT("BO", 0x30, 1, 0xF1), /* Bolivia */
542 COUNTRY_CHPLAN_ENT("BR", 0x34, 1, 0xF1), /* Brazil */
543 COUNTRY_CHPLAN_ENT("BS", 0x34, 1, 0x20), /* Bahamas */
544 COUNTRY_CHPLAN_ENT("BW", 0x26, 1, 0xF1), /* Botswana */
545 COUNTRY_CHPLAN_ENT("BY", 0x26, 1, 0xF1), /* Belarus */
546 COUNTRY_CHPLAN_ENT("BZ", 0x34, 1, 0x00), /* Belize */
547 COUNTRY_CHPLAN_ENT("CA", 0x34, 1, 0xFB), /* Canada */
548 COUNTRY_CHPLAN_ENT("CC", 0x26, 1, 0x00), /* Cocos (Keeling) Islands (Australia) */
549 COUNTRY_CHPLAN_ENT("CD", 0x26, 1, 0xB0), /* Congo, Republic of the */
550 COUNTRY_CHPLAN_ENT("CF", 0x26, 1, 0xB0), /* Central African Republic */
551 COUNTRY_CHPLAN_ENT("CG", 0x26, 1, 0xB0), /* Congo, Democratic Republic of the. Zaire */
552 COUNTRY_CHPLAN_ENT("CH", 0x26, 1, 0xFB), /* Switzerland */
553 COUNTRY_CHPLAN_ENT("CI", 0x26, 1, 0xF1), /* Cote d'Ivoire */
554 COUNTRY_CHPLAN_ENT("CK", 0x26, 1, 0x00), /* Cook Islands */
555 COUNTRY_CHPLAN_ENT("CL", 0x30, 1, 0xF1), /* Chile */
556 COUNTRY_CHPLAN_ENT("CM", 0x26, 1, 0xB0), /* Cameroon */
557 COUNTRY_CHPLAN_ENT("CN", 0x48, 1, 0xFB), /* China */
558 COUNTRY_CHPLAN_ENT("CO", 0x34, 1, 0xF1), /* Colombia */
559 COUNTRY_CHPLAN_ENT("CR", 0x34, 1, 0xF1), /* Costa Rica */
560 COUNTRY_CHPLAN_ENT("CV", 0x26, 1, 0xB0), /* Cape Verde */
561 COUNTRY_CHPLAN_ENT("CX", 0x45, 1, 0x00), /* Christmas Island (Australia) */
562 COUNTRY_CHPLAN_ENT("CY", 0x26, 1, 0xFB), /* Cyprus */
563 COUNTRY_CHPLAN_ENT("CZ", 0x26, 1, 0xFB), /* Czech Republic */
564 COUNTRY_CHPLAN_ENT("DE", 0x26, 1, 0xFB), /* Germany */
565 COUNTRY_CHPLAN_ENT("DJ", 0x26, 1, 0x80), /* Djibouti */
566 COUNTRY_CHPLAN_ENT("DK", 0x26, 1, 0xFB), /* Denmark */
567 COUNTRY_CHPLAN_ENT("DM", 0x34, 1, 0x00), /* Dominica */
568 COUNTRY_CHPLAN_ENT("DO", 0x34, 1, 0xF1), /* Dominican Republic */
569 COUNTRY_CHPLAN_ENT("DZ", 0x26, 1, 0xF1), /* Algeria */
570 COUNTRY_CHPLAN_ENT("EC", 0x34, 1, 0xF1), /* Ecuador */
571 COUNTRY_CHPLAN_ENT("EE", 0x26, 1, 0xFB), /* Estonia */
572 COUNTRY_CHPLAN_ENT("EG", 0x47, 0, 0xF1), /* Egypt */
573 COUNTRY_CHPLAN_ENT("EH", 0x47, 1, 0x80), /* Western Sahara */
574 COUNTRY_CHPLAN_ENT("ER", 0x26, 1, 0x00), /* Eritrea */
575 COUNTRY_CHPLAN_ENT("ES", 0x26, 1, 0xFB), /* Spain, Canary Islands, Ceuta, Melilla */
576 COUNTRY_CHPLAN_ENT("ET", 0x26, 1, 0xB0), /* Ethiopia */
577 COUNTRY_CHPLAN_ENT("FI", 0x26, 1, 0xFB), /* Finland */
578 COUNTRY_CHPLAN_ENT("FJ", 0x34, 1, 0x00), /* Fiji */
579 COUNTRY_CHPLAN_ENT("FK", 0x26, 1, 0x00), /* Falkland Islands (Islas Malvinas) (UK) */
580 COUNTRY_CHPLAN_ENT("FM", 0x34, 1, 0x00), /* Micronesia, Federated States of (USA) */
581 COUNTRY_CHPLAN_ENT("FO", 0x26, 1, 0x00), /* Faroe Islands (Denmark) */
582 COUNTRY_CHPLAN_ENT("FR", 0x26, 1, 0xFB), /* France */
583 COUNTRY_CHPLAN_ENT("GA", 0x26, 1, 0xB0), /* Gabon */
584 COUNTRY_CHPLAN_ENT("GB", 0x26, 1, 0xFB), /* Great Britain (United Kingdom; England) */
585 COUNTRY_CHPLAN_ENT("GD", 0x34, 1, 0xB0), /* Grenada */
586 COUNTRY_CHPLAN_ENT("GE", 0x26, 1, 0x00), /* Georgia */
587 COUNTRY_CHPLAN_ENT("GF", 0x26, 1, 0x80), /* French Guiana */
588 COUNTRY_CHPLAN_ENT("GG", 0x26, 1, 0x00), /* Guernsey (UK) */
589 COUNTRY_CHPLAN_ENT("GH", 0x26, 1, 0xF1), /* Ghana */
590 COUNTRY_CHPLAN_ENT("GI", 0x26, 1, 0x00), /* Gibraltar (UK) */
591 COUNTRY_CHPLAN_ENT("GL", 0x26, 1, 0x00), /* Greenland (Denmark) */
592 COUNTRY_CHPLAN_ENT("GM", 0x26, 1, 0xB0), /* Gambia */
593 COUNTRY_CHPLAN_ENT("GN", 0x26, 1, 0x10), /* Guinea */
594 COUNTRY_CHPLAN_ENT("GP", 0x26, 1, 0x00), /* Guadeloupe (France) */
595 COUNTRY_CHPLAN_ENT("GQ", 0x26, 1, 0xB0), /* Equatorial Guinea */
596 COUNTRY_CHPLAN_ENT("GR", 0x26, 1, 0xFB), /* Greece */
597 COUNTRY_CHPLAN_ENT("GS", 0x26, 1, 0x00), /* South Georgia and the Sandwich Islands (UK) */
598 COUNTRY_CHPLAN_ENT("GT", 0x34, 1, 0xF1), /* Guatemala */
599 COUNTRY_CHPLAN_ENT("GU", 0x34, 1, 0x00), /* Guam (USA) */
600 COUNTRY_CHPLAN_ENT("GW", 0x26, 1, 0xB0), /* Guinea-Bissau */
601 COUNTRY_CHPLAN_ENT("GY", 0x44, 1, 0x00), /* Guyana */
602 COUNTRY_CHPLAN_ENT("HK", 0x26, 1, 0xFB), /* Hong Kong */
603 COUNTRY_CHPLAN_ENT("HM", 0x45, 1, 0x00), /* Heard and McDonald Islands (Australia) */
604 COUNTRY_CHPLAN_ENT("HN", 0x32, 1, 0xF1), /* Honduras */
605 COUNTRY_CHPLAN_ENT("HR", 0x26, 1, 0xF9), /* Croatia */
606 COUNTRY_CHPLAN_ENT("HT", 0x34, 1, 0x50), /* Haiti */
607 COUNTRY_CHPLAN_ENT("HU", 0x26, 1, 0xFB), /* Hungary */
608 COUNTRY_CHPLAN_ENT("ID", 0x54, 0, 0xF3), /* Indonesia */
609 COUNTRY_CHPLAN_ENT("IE", 0x26, 1, 0xFB), /* Ireland */
610 COUNTRY_CHPLAN_ENT("IL", 0x47, 1, 0xF1), /* Israel */
611 COUNTRY_CHPLAN_ENT("IM", 0x26, 1, 0x00), /* Isle of Man (UK) */
612 COUNTRY_CHPLAN_ENT("IN", 0x47, 1, 0xF1), /* India */
613 COUNTRY_CHPLAN_ENT("IQ", 0x26, 1, 0x00), /* Iraq */
614 COUNTRY_CHPLAN_ENT("IR", 0x26, 0, 0x00), /* Iran */
615 COUNTRY_CHPLAN_ENT("IS", 0x26, 1, 0xFB), /* Iceland */
616 COUNTRY_CHPLAN_ENT("IT", 0x26, 1, 0xFB), /* Italy */
617 COUNTRY_CHPLAN_ENT("JE", 0x26, 1, 0x00), /* Jersey (UK) */
618 COUNTRY_CHPLAN_ENT("JM", 0x51, 1, 0xF1), /* Jamaica */
619 COUNTRY_CHPLAN_ENT("JO", 0x49, 1, 0xFB), /* Jordan */
620 COUNTRY_CHPLAN_ENT("JP", 0x27, 1, 0xFF), /* Japan- Telec */
621 COUNTRY_CHPLAN_ENT("KE", 0x47, 1, 0xF9), /* Kenya */
622 COUNTRY_CHPLAN_ENT("KG", 0x26, 1, 0xF1), /* Kyrgyzstan */
623 COUNTRY_CHPLAN_ENT("KH", 0x26, 1, 0xF1), /* Cambodia */
624 COUNTRY_CHPLAN_ENT("KI", 0x26, 1, 0x00), /* Kiribati */
625 COUNTRY_CHPLAN_ENT("KN", 0x34, 1, 0x00), /* Saint Kitts and Nevis */
626 COUNTRY_CHPLAN_ENT("KR", 0x28, 1, 0xFB), /* South Korea */
627 COUNTRY_CHPLAN_ENT("KW", 0x47, 1, 0xFB), /* Kuwait */
628 COUNTRY_CHPLAN_ENT("KY", 0x34, 1, 0x00), /* Cayman Islands (UK) */
629 COUNTRY_CHPLAN_ENT("KZ", 0x26, 1, 0x00), /* Kazakhstan */
630 COUNTRY_CHPLAN_ENT("LA", 0x26, 1, 0x00), /* Laos */
631 COUNTRY_CHPLAN_ENT("LB", 0x26, 1, 0xF1), /* Lebanon */
632 COUNTRY_CHPLAN_ENT("LC", 0x34, 1, 0x00), /* Saint Lucia */
633 COUNTRY_CHPLAN_ENT("LI", 0x26, 1, 0xFB), /* Liechtenstein */
634 COUNTRY_CHPLAN_ENT("LK", 0x26, 1, 0xF1), /* Sri Lanka */
635 COUNTRY_CHPLAN_ENT("LR", 0x26, 1, 0xB0), /* Liberia */
636 COUNTRY_CHPLAN_ENT("LS", 0x26, 1, 0xF1), /* Lesotho */
637 COUNTRY_CHPLAN_ENT("LT", 0x26, 1, 0xFB), /* Lithuania */
638 COUNTRY_CHPLAN_ENT("LU", 0x26, 1, 0xFB), /* Luxembourg */
639 COUNTRY_CHPLAN_ENT("LV", 0x26, 1, 0xFB), /* Latvia */
640 COUNTRY_CHPLAN_ENT("LY", 0x26, 1, 0x00), /* Libya */
641 COUNTRY_CHPLAN_ENT("MA", 0x47, 1, 0xF1), /* Morocco */
642 COUNTRY_CHPLAN_ENT("MC", 0x26, 1, 0xFB), /* Monaco */
643 COUNTRY_CHPLAN_ENT("MD", 0x26, 1, 0xF1), /* Moldova */
644 COUNTRY_CHPLAN_ENT("ME", 0x26, 1, 0xF1), /* Montenegro */
645 COUNTRY_CHPLAN_ENT("MF", 0x34, 1, 0x00), /* Saint Martin */
646 COUNTRY_CHPLAN_ENT("MG", 0x26, 1, 0x20), /* Madagascar */
647 COUNTRY_CHPLAN_ENT("MH", 0x34, 1, 0x00), /* Marshall Islands (USA) */
648 COUNTRY_CHPLAN_ENT("MK", 0x26, 1, 0xF1), /* Republic of Macedonia (FYROM) */
649 COUNTRY_CHPLAN_ENT("ML", 0x26, 1, 0xB0), /* Mali */
650 COUNTRY_CHPLAN_ENT("MM", 0x26, 1, 0x00), /* Burma (Myanmar) */
651 COUNTRY_CHPLAN_ENT("MN", 0x26, 1, 0x00), /* Mongolia */
652 COUNTRY_CHPLAN_ENT("MO", 0x26, 1, 0x00), /* Macau */
653 COUNTRY_CHPLAN_ENT("MP", 0x34, 1, 0x00), /* Northern Mariana Islands (USA) */
654 COUNTRY_CHPLAN_ENT("MQ", 0x26, 1, 0x40), /* Martinique (France) */
655 COUNTRY_CHPLAN_ENT("MR", 0x26, 1, 0xA0), /* Mauritania */
656 COUNTRY_CHPLAN_ENT("MS", 0x26, 1, 0x00), /* Montserrat (UK) */
657 COUNTRY_CHPLAN_ENT("MT", 0x26, 1, 0xFB), /* Malta */
658 COUNTRY_CHPLAN_ENT("MU", 0x26, 1, 0xB0), /* Mauritius */
659 COUNTRY_CHPLAN_ENT("MV", 0x26, 1, 0x00), /* Maldives */
660 COUNTRY_CHPLAN_ENT("MW", 0x26, 1, 0xB0), /* Malawi */
661 COUNTRY_CHPLAN_ENT("MX", 0x34, 1, 0xF1), /* Mexico */
662 COUNTRY_CHPLAN_ENT("MY", 0x47, 1, 0xF1), /* Malaysia */
663 COUNTRY_CHPLAN_ENT("MZ", 0x26, 1, 0xF1), /* Mozambique */
664 COUNTRY_CHPLAN_ENT("NA", 0x26, 0, 0x00), /* Namibia */
665 COUNTRY_CHPLAN_ENT("NC", 0x26, 1, 0x00), /* New Caledonia */
666 COUNTRY_CHPLAN_ENT("NE", 0x26, 1, 0xB0), /* Niger */
667 COUNTRY_CHPLAN_ENT("NF", 0x45, 1, 0x00), /* Norfolk Island (Australia) */
668 COUNTRY_CHPLAN_ENT("NG", 0x50, 1, 0xF9), /* Nigeria */
669 COUNTRY_CHPLAN_ENT("NI", 0x34, 1, 0xF1), /* Nicaragua */
670 COUNTRY_CHPLAN_ENT("NL", 0x26, 1, 0xFB), /* Netherlands */
671 COUNTRY_CHPLAN_ENT("NO", 0x26, 1, 0xFB), /* Norway */
672 COUNTRY_CHPLAN_ENT("NP", 0x47, 1, 0xF0), /* Nepal */
673 COUNTRY_CHPLAN_ENT("NR", 0x26, 1, 0x00), /* Nauru */
674 COUNTRY_CHPLAN_ENT("NU", 0x45, 1, 0x00), /* Niue */
675 COUNTRY_CHPLAN_ENT("NZ", 0x45, 1, 0xFB), /* New Zealand */
676 COUNTRY_CHPLAN_ENT("OM", 0x26, 1, 0xF9), /* Oman */
677 COUNTRY_CHPLAN_ENT("PA", 0x34, 1, 0xF1), /* Panama */
678 COUNTRY_CHPLAN_ENT("PE", 0x34, 1, 0xF1), /* Peru */
679 COUNTRY_CHPLAN_ENT("PF", 0x26, 1, 0x00), /* French Polynesia (France) */
680 COUNTRY_CHPLAN_ENT("PG", 0x26, 1, 0xF1), /* Papua New Guinea */
681 COUNTRY_CHPLAN_ENT("PH", 0x26, 1, 0xF1), /* Philippines */
682 COUNTRY_CHPLAN_ENT("PK", 0x51, 1, 0xF1), /* Pakistan */
683 COUNTRY_CHPLAN_ENT("PL", 0x26, 1, 0xFB), /* Poland */
684 COUNTRY_CHPLAN_ENT("PM", 0x26, 1, 0x00), /* Saint Pierre and Miquelon (France) */
685 COUNTRY_CHPLAN_ENT("PR", 0x34, 1, 0xF1), /* Puerto Rico */
686 COUNTRY_CHPLAN_ENT("PT", 0x26, 1, 0xFB), /* Portugal */
687 COUNTRY_CHPLAN_ENT("PW", 0x34, 1, 0x00), /* Palau */
688 COUNTRY_CHPLAN_ENT("PY", 0x34, 1, 0xF1), /* Paraguay */
689 COUNTRY_CHPLAN_ENT("QA", 0x51, 1, 0xF9), /* Qatar */
690 COUNTRY_CHPLAN_ENT("RE", 0x26, 1, 0x00), /* Reunion (France) */
691 COUNTRY_CHPLAN_ENT("RO", 0x26, 1, 0xF1), /* Romania */
692 COUNTRY_CHPLAN_ENT("RS", 0x26, 1, 0xF1), /* Serbia, Kosovo */
693 COUNTRY_CHPLAN_ENT("RU", 0x59, 1, 0xFB), /* Russia(fac/gost), Kaliningrad */
694 COUNTRY_CHPLAN_ENT("RW", 0x26, 1, 0xB0), /* Rwanda */
695 COUNTRY_CHPLAN_ENT("SA", 0x26, 1, 0xFB), /* Saudi Arabia */
696 COUNTRY_CHPLAN_ENT("SB", 0x26, 1, 0x00), /* Solomon Islands */
697 COUNTRY_CHPLAN_ENT("SC", 0x34, 1, 0x90), /* Seychelles */
698 COUNTRY_CHPLAN_ENT("SE", 0x26, 1, 0xFB), /* Sweden */
699 COUNTRY_CHPLAN_ENT("SG", 0x47, 1, 0xFB), /* Singapore */
700 COUNTRY_CHPLAN_ENT("SH", 0x26, 1, 0x00), /* Saint Helena (UK) */
701 COUNTRY_CHPLAN_ENT("SI", 0x26, 1, 0xFB), /* Slovenia */
702 COUNTRY_CHPLAN_ENT("SJ", 0x26, 1, 0x00), /* Svalbard (Norway) */
703 COUNTRY_CHPLAN_ENT("SK", 0x26, 1, 0xFB), /* Slovakia */
704 COUNTRY_CHPLAN_ENT("SL", 0x26, 1, 0xB0), /* Sierra Leone */
705 COUNTRY_CHPLAN_ENT("SM", 0x26, 1, 0x00), /* San Marino */
706 COUNTRY_CHPLAN_ENT("SN", 0x26, 1, 0xF1), /* Senegal */
707 COUNTRY_CHPLAN_ENT("SO", 0x26, 1, 0x00), /* Somalia */
708 COUNTRY_CHPLAN_ENT("SR", 0x34, 1, 0x00), /* Suriname */
709 COUNTRY_CHPLAN_ENT("ST", 0x34, 1, 0x80), /* Sao Tome and Principe */
710 COUNTRY_CHPLAN_ENT("SV", 0x30, 1, 0xF1), /* El Salvador */
711 COUNTRY_CHPLAN_ENT("SX", 0x34, 1, 0x00), /* Sint Marteen */
712 COUNTRY_CHPLAN_ENT("SZ", 0x26, 1, 0x20), /* Swaziland */
713 COUNTRY_CHPLAN_ENT("TC", 0x26, 1, 0x00), /* Turks and Caicos Islands (UK) */
714 COUNTRY_CHPLAN_ENT("TD", 0x26, 1, 0xB0), /* Chad */
715 COUNTRY_CHPLAN_ENT("TF", 0x26, 1, 0x80), /* French Southern and Antarctic Lands (FR Southern Territories) */
716 COUNTRY_CHPLAN_ENT("TG", 0x26, 1, 0xB0), /* Togo */
717 COUNTRY_CHPLAN_ENT("TH", 0x26, 1, 0xF1), /* Thailand */
718 COUNTRY_CHPLAN_ENT("TJ", 0x26, 1, 0x40), /* Tajikistan */
719 COUNTRY_CHPLAN_ENT("TK", 0x45, 1, 0x00), /* Tokelau */
720 COUNTRY_CHPLAN_ENT("TM", 0x26, 1, 0x00), /* Turkmenistan */
721 COUNTRY_CHPLAN_ENT("TN", 0x47, 1, 0xF1), /* Tunisia */
722 COUNTRY_CHPLAN_ENT("TO", 0x26, 1, 0x00), /* Tonga */
723 COUNTRY_CHPLAN_ENT("TR", 0x26, 1, 0xF1), /* Turkey, Northern Cyprus */
724 COUNTRY_CHPLAN_ENT("TT", 0x42, 1, 0xF1), /* Trinidad & Tobago */
725 COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0xFF), /* Taiwan */
726 COUNTRY_CHPLAN_ENT("TZ", 0x26, 1, 0xF0), /* Tanzania */
727 COUNTRY_CHPLAN_ENT("UA", 0x26, 1, 0xFB), /* Ukraine */
728 COUNTRY_CHPLAN_ENT("UG", 0x26, 1, 0xF1), /* Uganda */
729 COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0xFF), /* United States of America (USA) */
730 COUNTRY_CHPLAN_ENT("UY", 0x34, 1, 0xF1), /* Uruguay */
731 COUNTRY_CHPLAN_ENT("UZ", 0x47, 1, 0xF0), /* Uzbekistan */
732 COUNTRY_CHPLAN_ENT("VA", 0x26, 1, 0x00), /* Holy See (Vatican City) */
733 COUNTRY_CHPLAN_ENT("VC", 0x34, 1, 0x10), /* Saint Vincent and the Grenadines */
734 COUNTRY_CHPLAN_ENT("VE", 0x30, 1, 0xF1), /* Venezuela */
735 COUNTRY_CHPLAN_ENT("VI", 0x34, 1, 0x00), /* United States Virgin Islands (USA) */
736 COUNTRY_CHPLAN_ENT("VN", 0x26, 1, 0xF1), /* Vietnam */
737 COUNTRY_CHPLAN_ENT("VU", 0x26, 1, 0x00), /* Vanuatu */
738 COUNTRY_CHPLAN_ENT("WF", 0x26, 1, 0x00), /* Wallis and Futuna (France) */
739 COUNTRY_CHPLAN_ENT("WS", 0x34, 1, 0x00), /* Samoa */
740 COUNTRY_CHPLAN_ENT("YE", 0x26, 1, 0x40), /* Yemen */
741 COUNTRY_CHPLAN_ENT("YT", 0x26, 1, 0x80), /* Mayotte (France) */
742 COUNTRY_CHPLAN_ENT("ZA", 0x26, 1, 0xF1), /* South Africa */
743 COUNTRY_CHPLAN_ENT("ZM", 0x26, 1, 0xB0), /* Zambia */
744 COUNTRY_CHPLAN_ENT("ZW", 0x26, 1, 0xF1), /* Zimbabwe */
747 u16 const country_chplan_map_sz = sizeof(country_chplan_map) / sizeof(struct country_chplan);
750 * rtw_get_chplan_from_country -
751 * @country_code: string of country code
753 * Return pointer of struct country_chplan entry or NULL when unsupported country_code is given
755 const struct country_chplan *rtw_get_chplan_from_country(const char *country_code)
757 const struct country_chplan *ent = NULL;
758 const struct country_chplan *map = NULL;
763 code[0] = alpha_to_upper(country_code[0]);
764 code[1] = alpha_to_upper(country_code[1]);
766 #if !defined(CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP) && RTW_DEF_MODULE_REGULATORY_CERT
767 ent = rtw_def_module_get_chplan_from_country(code);
772 #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
773 map = CUSTOMIZED_country_chplan_map;
774 map_sz = CUSTOMIZED_country_chplan_map_sz;
776 map = country_chplan_map;
777 map_sz = country_chplan_map_sz;
780 for (i = 0; i < map_sz; i++) {
781 if (strncmp(code, map[i].alpha2, 2) == 0) {
788 #if RTW_DEF_MODULE_REGULATORY_CERT
789 if (ent && !(COUNTRY_CHPLAN_DEF_MODULE_FALGS(ent) & RTW_DEF_MODULE_REGULATORY_CERT))
796 int rtw_ch_to_bb_gain_sel(int ch)
800 if (ch >= 1 && ch <= 14)
802 #ifdef CONFIG_IEEE80211_BAND_5GHZ
803 else if (ch >= 36 && ch < 48)
805 else if (ch >= 52 && ch <= 64)
807 else if (ch >= 100 && ch <= 120)
809 else if (ch >= 124 && ch <= 144)
811 else if (ch >= 149 && ch <= 177)
818 s8 rtw_rf_get_kfree_tx_gain_offset(_adapter *padapter, u8 path, u8 ch)
822 #ifdef CONFIG_RF_POWER_TRIM
823 HAL_DATA_TYPE *hal_data = GET_HAL_DATA(padapter);
824 struct kfree_data_t *kfree_data = GET_KFREE_DATA(padapter);
825 s8 bb_gain_sel = rtw_ch_to_bb_gain_sel(ch);
827 if (bb_gain_sel < BB_GAIN_2G || bb_gain_sel >= BB_GAIN_NUM) {
832 if (kfree_data->flag & KFREE_FLAG_ON) {
833 kfree_offset = kfree_data->bb_gain[bb_gain_sel][path];
835 RTW_INFO("%s path:%u, ch:%u, bb_gain_sel:%d, kfree_offset:%d\n"
836 , __func__, path, ch, bb_gain_sel, kfree_offset);
839 #endif /* CONFIG_RF_POWER_TRIM */
843 void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset)
847 RTW_INFO("kfree gain_offset 0x55:0x%x ", rtw_hal_read_rfreg(adapter, path, 0x55, 0xffffffff));
848 switch (rtw_get_chip_type(adapter)) {
849 #ifdef CONFIG_RTL8723D
851 write_value = RF_TX_GAIN_OFFSET_8723D(offset);
852 rtw_hal_write_rfreg(adapter, path, 0x55, 0x0fc000, write_value);
854 #endif /* CONFIG_RTL8723D */
855 #ifdef CONFIG_RTL8703B
857 write_value = RF_TX_GAIN_OFFSET_8703B(offset);
858 rtw_hal_write_rfreg(adapter, path, 0x55, 0x0fc000, write_value);
860 #endif /* CONFIG_RTL8703B */
861 #ifdef CONFIG_RTL8188F
863 write_value = RF_TX_GAIN_OFFSET_8188F(offset);
864 rtw_hal_write_rfreg(adapter, path, 0x55, 0x0fc000, write_value);
866 #endif /* CONFIG_RTL8188F */
867 #ifdef CONFIG_RTL8192E
869 write_value = RF_TX_GAIN_OFFSET_8192E(offset);
870 rtw_hal_write_rfreg(adapter, path, 0x55, 0x0f8000, write_value);
872 #endif /* CONFIG_RTL8188F */
874 #ifdef CONFIG_RTL8821A
876 write_value = RF_TX_GAIN_OFFSET_8821A(offset);
877 rtw_hal_write_rfreg(adapter, path, 0x55, 0x0f8000, write_value);
879 #endif /* CONFIG_RTL8821A */
880 #if defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C)
884 RTW_INFO("\nkfree by PhyDM on the sw CH. path %d\n", path);
886 #endif /* CONFIG_RTL8814A || CONFIG_RTL8822B || CONFIG_RTL8821C */
893 RTW_INFO(" after :0x%x\n", rtw_hal_read_rfreg(adapter, path, 0x55, 0xffffffff));
896 void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch)
898 HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
900 s8 tx_pwr_track_offset = 0; /* TODO: 8814A should consider tx pwr track when setting tx gain offset */
904 for (i = 0; i < hal_data->NumTotalRFPath; i++) {
905 kfree_offset = rtw_rf_get_kfree_tx_gain_offset(adapter, i, ch);
906 total_offset = kfree_offset + tx_pwr_track_offset;
907 rtw_rf_set_tx_gain_offset(adapter, i, total_offset);
911 bool rtw_is_dfs_range(u32 hi, u32 lo)
913 return rtw_is_range_overlap(hi, lo, 5720 + 10, 5260 - 10) ? _TRUE : _FALSE;
916 bool rtw_is_dfs_ch(u8 ch, u8 bw, u8 offset)
920 if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
923 return rtw_is_dfs_range(hi, lo) ? _TRUE : _FALSE;
926 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region)
928 return (dfs_region == PHYDM_DFS_DOMAIN_ETSI && rtw_is_range_overlap(hi, lo, 5660 + 10, 5600 - 10)) ? _TRUE : _FALSE;
931 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region)
935 if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
938 return rtw_is_long_cac_range(hi, lo, dfs_region) ? _TRUE : _FALSE;