wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / combo_mt66xx / mt6620 / wlan / mgmt / rlm_domain.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/rlm_domain.c#1 $
3 */
4
5 /*! \file   "rlm_domain.c"
6     \brief
7
8 */
9
10
11
12 /*
13 ** $Log: rlm_domain.c $
14  *
15  * 11 10 2011 cm.chang
16  * NULL
17  * Modify debug message for XLOG
18  *
19  * 09 29 2011 cm.chang
20  * NULL
21  * Change the function prototype of rlmDomainGetChnlList()
22  *
23  * 09 23 2011 cm.chang
24  * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
25  * Let channel number to zero if band is illegal
26  *
27  * 09 22 2011 cm.chang
28  * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
29  * Exclude channel list with illegal band
30  *
31  * 09 15 2011 cm.chang
32  * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
33  * Use defined country group to have a change to add new group
34  *
35  * 09 08 2011 cm.chang
36  * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
37  * Use new fields ucChannelListMap and ucChannelListIndex in NVRAM
38  *
39  * 08 31 2011 cm.chang
40  * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
41  * .
42  *
43  * 06 01 2011 cm.chang
44  * [WCXRP00000756] [MT6620 Wi-Fi][Driver] 1. AIS follow channel of BOW 2. Provide legal channel function
45  * Provide legal channel function based on domain
46  *
47  * 03 19 2011 yuche.tsai
48  * [WCXRP00000584] [Volunteer Patch][MT6620][Driver] Add beacon timeout support for WiFi Direct.
49  * Add beacon timeout support for WiFi Direct Network.
50  *
51  * 03 02 2011 terry.wu
52  * [WCXRP00000505] [MT6620 Wi-Fi][Driver/FW] WiFi Direct Integration
53  * Export rlmDomainGetDomainInfo for p2p driver.
54  *
55  * 01 12 2011 cm.chang
56  * [WCXRP00000354] [MT6620 Wi-Fi][Driver][FW] Follow NVRAM bandwidth setting
57  * User-defined bandwidth is for 2.4G and 5G individually
58  *
59  * 12 07 2010 cm.chang
60  * [WCXRP00000238] MT6620 Wi-Fi][Driver][FW] Support regulation domain setting from NVRAM and supplicant
61  * 1. Country code is from NVRAM or supplicant
62  * 2. Change band definition in CMD/EVENT.
63  *
64  * 07 08 2010 cp.wu
65  *
66  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
67  *
68  * 07 08 2010 cm.chang
69  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
70  * Check draft RLM code for HT cap
71  *
72  * 03 25 2010 cm.chang
73  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
74  * Filter out not supported RF freq when reporting available chnl list
75  *
76  * 01 22 2010 cm.chang
77  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
78  * Support protection and bandwidth switch
79  *
80  * 01 13 2010 cm.chang
81  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
82  * Provide query function about full channle list.
83  *
84  * Dec 1 2009 mtk01104
85  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
86  *
87  *
88 **
89 */
90
91 /*******************************************************************************
92 *                         C O M P I L E R   F L A G S
93 ********************************************************************************
94 */
95
96 /*******************************************************************************
97 *                    E X T E R N A L   R E F E R E N C E S
98 ********************************************************************************
99 */
100 #include "precomp.h"
101
102 /*******************************************************************************
103 *                              C O N S T A N T S
104 ********************************************************************************
105 */
106
107 /*******************************************************************************
108 *                             D A T A   T Y P E S
109 ********************************************************************************
110 */
111
112 /*******************************************************************************
113 *                            P U B L I C   D A T A
114 ********************************************************************************
115 */
116
117 /* The following country or domain shall be set from host driver.
118  * And host driver should pass specified DOMAIN_INFO_ENTRY to MT6620 as
119  * the channel list of being a STA to do scanning/searching AP or being an
120  * AP to choose an adequate channel if auto-channel is set.
121  */
122
123 /* Define mapping tables between country code and its channel set
124  */
125 static const UINT_16     g_u2CountryGroup0[] =
126 {
127     COUNTRY_CODE_US, COUNTRY_CODE_BS, COUNTRY_CODE_BB, COUNTRY_CODE_BO, COUNTRY_CODE_DM,
128     COUNTRY_CODE_DO, COUNTRY_CODE_HT, COUNTRY_CODE_PR, COUNTRY_CODE_TH, COUNTRY_CODE_TW,
129     COUNTRY_CODE_AI, COUNTRY_CODE_AG, COUNTRY_CODE_AW, COUNTRY_CODE_BM, COUNTRY_CODE_CU,
130     COUNTRY_CODE_GD, COUNTRY_CODE_GY, COUNTRY_CODE_JM, COUNTRY_CODE_KN, COUNTRY_CODE_LC,
131     COUNTRY_CODE_VC, COUNTRY_CODE_TT, COUNTRY_CODE_SR
132 };
133 static const UINT_16     g_u2CountryGroup1[] =
134 {
135     COUNTRY_CODE_BR, COUNTRY_CODE_EC, COUNTRY_CODE_HK, COUNTRY_CODE_MX, COUNTRY_CODE_PE,
136     COUNTRY_CODE_CR, COUNTRY_CODE_MD, COUNTRY_CODE_NI, COUNTRY_CODE_PZ
137 };
138 static const UINT_16     g_u2CountryGroup2[] = {COUNTRY_CODE_CO, COUNTRY_CODE_PY};
139 static const UINT_16     g_u2CountryGroup3[] = {COUNTRY_CODE_JP};
140 static const UINT_16     g_u2CountryGroup4[] =
141 {
142     COUNTRY_CODE_CN, COUNTRY_CODE_UY, COUNTRY_CODE_MA
143 };
144 static const UINT_16     g_u2CountryGroup5[] = {COUNTRY_CODE_AR};
145 static const UINT_16     g_u2CountryGroup6[] = {COUNTRY_CODE_AU, COUNTRY_CODE_NZ};
146 static const UINT_16     g_u2CountryGroup7[] = {COUNTRY_CODE_RU};
147 static const UINT_16     g_u2CountryGroup8[] =
148 {
149     COUNTRY_CODE_ID, COUNTRY_CODE_HN, COUNTRY_CODE_PG, COUNTRY_CODE_PK
150 };
151 static const UINT_16     g_u2CountryGroup9[] = {COUNTRY_CODE_CA};
152 static const UINT_16     g_u2CountryGroup10[] =
153 {
154     COUNTRY_CODE_CL, COUNTRY_CODE_IN, COUNTRY_CODE_SA, COUNTRY_CODE_SG, COUNTRY_CODE_VE,
155     COUNTRY_CODE_MY, COUNTRY_CODE_VN, COUNTRY_CODE_EG
156 };
157 static const UINT_16     g_u2CountryGroup11[] = {COUNTRY_CODE_IL, COUNTRY_CODE_UA};
158 static const UINT_16     g_u2CountryGroup12[] = {COUNTRY_CODE_JO, COUNTRY_CODE_KW};
159 static const UINT_16     g_u2CountryGroup13[] = {COUNTRY_CODE_KR, COUNTRY_CODE_OM};
160 static const UINT_16     g_u2CountryGroup14[] =
161 {
162     COUNTRY_CODE_EU
163     /* When country code is not found, this domain info will be used.
164      * So mark all country codes to reduce search time. 20110908
165      */
166     /*, COUNTRY_CODE_PH, COUNTRY_CODE_TR, COUNTRY_CODE_IR, COUNTRY_CODE_BY,
167     COUNTRY_CODE_LK */
168 };
169
170
171 DOMAIN_INFO_ENTRY arSupportedRegDomains[] = {
172     {
173         (PUINT_16) g_u2CountryGroup0, sizeof(g_u2CountryGroup0) / 2,
174         {
175             {  81, BAND_2G4, CHNL_SPAN_5,    1,  11,  FALSE }, /* CH_SET_2G4_1_11 */
176
177             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
178             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
179             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
180             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
181             {   0, BAND_NULL,           0,   0,   0,  FALSE }
182         }
183     },
184     {
185         (PUINT_16) g_u2CountryGroup1, sizeof(g_u2CountryGroup1) / 2,
186         {
187             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
188
189             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
190             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
191             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
192             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
193             {   0, BAND_NULL,           0,   0,   0,  FALSE }
194         }
195     },
196     {
197         (PUINT_16) g_u2CountryGroup2, sizeof(g_u2CountryGroup2) / 2,
198         {
199             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
200
201             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
202             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
203             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
204             { 125, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_UPPER_NA */
205             {   0, BAND_NULL,           0,   0,   0,  FALSE }
206         }
207     },
208     {
209         (PUINT_16) g_u2CountryGroup3, sizeof(g_u2CountryGroup3) / 2,
210         {
211             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_14 */
212             {  82, BAND_2G4, CHNL_SPAN_5,   14,   1,  FALSE },
213
214             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
215             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
216             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
217             { 125, BAND_NULL,           0,   0,   0,  FALSE }  /* CH_SET_UNII_UPPER_NA */
218         }
219     },
220     {
221         (PUINT_16) g_u2CountryGroup4, sizeof(g_u2CountryGroup4) / 2,
222         {
223             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
224
225             { 115, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_LOW_NA */
226             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
227             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
228             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
229             {   0, BAND_NULL,           0,   0,   0,  FALSE }
230         }
231     },
232     {
233         (PUINT_16) g_u2CountryGroup5, sizeof(g_u2CountryGroup5) / 2,
234         {
235             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
236
237             { 115, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_LOW_NA */
238             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
239             { 121, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_WW_NA */
240             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
241             {   0, BAND_NULL,           0,   0,   0,  FALSE }
242         }
243     },
244     {
245         (PUINT_16) g_u2CountryGroup6, sizeof(g_u2CountryGroup6) / 2,
246         {
247             {  81, BAND_2G4, CHNL_SPAN_5,    1,  11,  FALSE }, /* CH_SET_2G4_1_11 */
248
249             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
250             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
251             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
252             { 125, BAND_5G,  CHNL_SPAN_20, 149,   4,  FALSE }, /* CH_SET_UNII_UPPER_149_161 */
253             {   0, BAND_NULL,           0,   0,   0,  FALSE }
254         }
255     },
256     {
257         (PUINT_16) g_u2CountryGroup7, sizeof(g_u2CountryGroup7) / 2,
258         {
259             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
260
261             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
262             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
263             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
264             { 125, BAND_5G,  CHNL_SPAN_20, 149,   4,  FALSE }, /* CH_SET_UNII_UPPER_149_161 */
265             {   0, BAND_NULL,           0,   0,   0,  FALSE }
266         }
267     },
268     {
269         (PUINT_16) g_u2CountryGroup8, sizeof(g_u2CountryGroup8) / 2,
270         {
271             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
272
273             { 115, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_LOW_NA */
274             { 118, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_MID_NA */
275             { 121, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_WW_NA */
276             { 125, BAND_5G,  CHNL_SPAN_20, 149,   4,  FALSE }, /* CH_SET_UNII_UPPER_149_161 */
277             {   0, BAND_NULL,           0,   0,   0,  FALSE }
278         }
279     },
280     {
281         (PUINT_16) g_u2CountryGroup9, sizeof(g_u2CountryGroup9) / 2,
282         {
283             {  81, BAND_2G4, CHNL_SPAN_5,    1,  11,  FALSE }, /* CH_SET_2G4_1_11 */
284
285             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
286             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
287             { 121, BAND_5G,  CHNL_SPAN_20, 100,   5,  FALSE }, /* CH_SET_UNII_WW_100_116_132_140 */
288             { 121, BAND_5G,  CHNL_SPAN_20, 132,   5,  FALSE },
289             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
290         }
291     },
292     {
293         (PUINT_16) g_u2CountryGroup10, sizeof(g_u2CountryGroup10) / 2,
294         {
295             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
296
297             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
298             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
299             { 121, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_WW_NA */
300             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
301             {   0, BAND_NULL,           0,   0,   0,  FALSE }
302         }
303     },
304     {
305         (PUINT_16) g_u2CountryGroup11, sizeof(g_u2CountryGroup11) / 2,
306         {
307             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
308
309             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
310             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
311             { 121, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_WW_NA */
312             { 125, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_UPPER_NA */
313             {   0, BAND_NULL,           0,   0,   0,  FALSE }
314         }
315     },
316     {
317         (PUINT_16) g_u2CountryGroup12, sizeof(g_u2CountryGroup12) / 2,
318         {
319             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
320
321             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
322             { 118, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_MID_NA */
323             { 121, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_WW_NA */
324             { 125, BAND_NULL,           0,   0,   0,  FALSE }, /* CH_SET_UNII_UPPER_NA */
325             {   0, BAND_NULL,           0,   0,   0,  FALSE }
326         }
327     },
328     {
329         (PUINT_16) g_u2CountryGroup13, sizeof(g_u2CountryGroup13) / 2,
330         {
331             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
332
333             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
334             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
335             { 121, BAND_5G,  CHNL_SPAN_20, 100,   8,  FALSE }, /* CH_SET_UNII_WW_100_128 */
336             { 125, BAND_5G,  CHNL_SPAN_20, 149,   5,  FALSE }, /* CH_SET_UNII_UPPER_149_165 */
337             {   0, BAND_NULL,           0,   0,   0,  FALSE }
338         }
339     },
340     {
341         /* Note: The final one is for Europe union now. */
342         (PUINT_16) g_u2CountryGroup14, sizeof(g_u2CountryGroup14) / 2,
343         {
344             {  81, BAND_2G4, CHNL_SPAN_5,    1,  13,  FALSE }, /* CH_SET_2G4_1_13 */
345
346             { 115, BAND_5G,  CHNL_SPAN_20,  36,   4,  FALSE }, /* CH_SET_UNII_LOW_36_48 */
347             { 118, BAND_5G,  CHNL_SPAN_20,  52,   4,  FALSE }, /* CH_SET_UNII_MID_52_64 */
348             { 121, BAND_5G,  CHNL_SPAN_20, 100,  11,  FALSE }, /* CH_SET_UNII_WW_100_140 */
349             { 125, BAND_5G,  CHNL_SPAN_20, 149,   7,  FALSE }, /* CH_SET_UNII_UPPER_149_173 */
350             {   0, BAND_NULL,           0,   0,   0,  FALSE }
351         }
352     }
353 };
354
355 #if 0
356 COUNTRY_CH_SET_T arCountryChSets[] = {
357     /* idx=0: US, Bahamas, Barbados, Bolivia(Voluntary), Dominica (the Commonwealth of Dominica),
358        The Dominican Republic, Haiti */
359     {CH_SET_2G4_1_11,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
360      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_149_165},
361     /* idx=1: Brazil, Ecuador, Hong Kong, Mexico, Peru */
362     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
363      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_149_165},
364     /* idx=2: JP1, Colombia(Voluntary), Paraguay */
365     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
366      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_NA},
367     /* idx=3: JP2 */
368     {CH_SET_2G4_1_14,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
369      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_NA},
370     /* idx=4: CN, Uruguay, Morocco */
371     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_NA,             CH_SET_UNII_MID_NA,
372      CH_SET_UNII_WW_NA,         CH_SET_UNII_UPPER_149_165},
373     /* idx=5: Argentina */
374     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_NA,             CH_SET_UNII_MID_52_64,
375      CH_SET_UNII_WW_NA,         CH_SET_UNII_UPPER_149_165},
376     /* idx=6: Australia, New Zealand */
377     {CH_SET_2G4_1_11,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
378      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_149_161},
379     /* idx=7: Russia */
380     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
381      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_149_161},
382     /* idx=8: Indonesia */
383     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_NA,             CH_SET_UNII_MID_NA,
384      CH_SET_UNII_WW_NA,         CH_SET_UNII_UPPER_149_161},
385     /* idx=9: Canada */
386     {CH_SET_2G4_1_11,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
387      CH_SET_UNII_WW_100_116_132_140,    CH_SET_UNII_UPPER_149_165},
388     /* idx=10: Chile, India, Saudi Arabia, Singapore */
389     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
390      CH_SET_UNII_WW_NA,         CH_SET_UNII_UPPER_149_165},
391     /* idx=11: Israel, Ukraine */
392     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
393      CH_SET_UNII_WW_NA,         CH_SET_UNII_UPPER_NA},
394     /* idx=12: Jordan, Kuwait */
395     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_NA,
396      CH_SET_UNII_WW_NA,         CH_SET_UNII_UPPER_NA},
397     /* idx=13: South Korea */
398     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
399      CH_SET_UNII_WW_100_128,    CH_SET_UNII_UPPER_149_165},
400     /* idx=14: Taiwan */
401     {CH_SET_2G4_1_11,           CH_SET_UNII_LOW_NA,             CH_SET_UNII_MID_52_64,
402      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_149_165},
403     /* idx=15: EU all countries */
404     {CH_SET_2G4_1_13,           CH_SET_UNII_LOW_36_48,          CH_SET_UNII_MID_52_64,
405      CH_SET_UNII_WW_100_140,    CH_SET_UNII_UPPER_149_173}
406 };
407 #endif
408
409
410 /*******************************************************************************
411 *                           P R I V A T E   D A T A
412 ********************************************************************************
413 */
414
415 /*******************************************************************************
416 *                                 M A C R O S
417 ********************************************************************************
418 */
419
420 /*******************************************************************************
421 *                   F U N C T I O N   D E C L A R A T I O N S
422 ********************************************************************************
423 */
424
425 /*******************************************************************************
426 *                              F U N C T I O N S
427 ********************************************************************************
428 */
429
430 /*----------------------------------------------------------------------------*/
431 /*!
432 * \brief
433 *
434 * \param[in/out]
435 *
436 * \return none
437 */
438 /*----------------------------------------------------------------------------*/
439 P_DOMAIN_INFO_ENTRY
440 rlmDomainGetDomainInfo (
441     P_ADAPTER_T     prAdapter
442     )
443 {
444 #define REG_DOMAIN_DEF_IDX          14  /* EU (Europe Union) */
445 #define REG_DOMAIN_GROUP_NUM \
446         (sizeof(arSupportedRegDomains) / sizeof(DOMAIN_INFO_ENTRY))
447
448     UINT_16                 i, j;
449     P_DOMAIN_INFO_ENTRY     prDomainInfo;
450     P_REG_INFO_T            prRegInfo;
451     UINT_16                 u2TargetCountryCode;
452
453     ASSERT(prAdapter);
454
455     if (prAdapter->prDomainInfo) {
456         return prAdapter->prDomainInfo;
457     }
458
459     prRegInfo = &prAdapter->prGlueInfo->rRegInfo;
460
461     DBGLOG(RLM, INFO, ("Domain: map=%d, idx=%d, code=0x%04x\n",
462         prRegInfo->eRegChannelListMap, prRegInfo->ucRegChannelListIndex,
463         prAdapter->rWifiVar.rConnSettings.u2CountryCode));
464
465     if (prRegInfo->eRegChannelListMap == REG_CH_MAP_TBL_IDX &&
466         prRegInfo->ucRegChannelListIndex < REG_DOMAIN_GROUP_NUM) {
467         prDomainInfo = &arSupportedRegDomains[prRegInfo->ucRegChannelListIndex];
468         goto L_set_domain_info;
469     }
470     else if (prRegInfo->eRegChannelListMap == REG_CH_MAP_CUSTOMIZED) {
471         prDomainInfo = &prRegInfo->rDomainInfo;
472         goto L_set_domain_info;
473     }
474
475     u2TargetCountryCode = prAdapter->rWifiVar.rConnSettings.u2CountryCode;
476
477     /* If no matched country code, the final one will be used
478      * The final one is for Europe union now.
479      */
480     for (i = 0; i < REG_DOMAIN_GROUP_NUM; i++) {
481         prDomainInfo = &arSupportedRegDomains[i];
482
483         ASSERT((prDomainInfo->u4CountryNum && prDomainInfo->pu2CountryGroup) ||
484                prDomainInfo->u4CountryNum == 0);
485
486         for (j = 0; j < prDomainInfo->u4CountryNum; j++) {
487             if (prDomainInfo->pu2CountryGroup[j] == u2TargetCountryCode) {
488                 break;
489             }
490         }
491         if (j < prDomainInfo->u4CountryNum) {
492             break; /* Found */
493         }
494     }
495
496     DATA_STRUC_INSPECTING_ASSERT(REG_DOMAIN_DEF_IDX < REG_DOMAIN_GROUP_NUM);
497
498     if (i >= REG_DOMAIN_GROUP_NUM) {
499         prDomainInfo = &arSupportedRegDomains[REG_DOMAIN_DEF_IDX];
500     }
501
502 L_set_domain_info:
503
504     prAdapter->prDomainInfo = prDomainInfo;
505     return prDomainInfo;
506 }
507
508 /*----------------------------------------------------------------------------*/
509 /*!
510 * \brief
511 *
512 * \param[in/out] The input variable pointed by pucNumOfChannel is the max
513 *                arrary size. The return value indciates meaning list size.
514 *
515 * \return none
516 */
517 /*----------------------------------------------------------------------------*/
518 VOID
519 rlmDomainGetChnlList (
520     P_ADAPTER_T             prAdapter,
521     ENUM_BAND_T             eSpecificBand,
522     UINT_8                  ucMaxChannelNum,
523     PUINT_8                 pucNumOfChannel,
524     P_RF_CHANNEL_INFO_T     paucChannelList
525     )
526 {
527     UINT_8                  i, j, ucNum;
528     P_DOMAIN_SUBBAND_INFO   prSubband;
529     P_DOMAIN_INFO_ENTRY     prDomainInfo;
530
531     ASSERT(prAdapter);
532     ASSERT(paucChannelList);
533     ASSERT(pucNumOfChannel);
534
535     /* If no matched country code, the final one will be used */
536     prDomainInfo = rlmDomainGetDomainInfo(prAdapter);
537     ASSERT(prDomainInfo);
538
539     ucNum = 0;
540     for (i = 0; i < MAX_SUBBAND_NUM; i++) {
541         prSubband = &prDomainInfo->rSubBand[i];
542
543         if (prSubband->ucBand == BAND_NULL || prSubband->ucBand >= BAND_NUM ||
544             (prSubband->ucBand == BAND_5G && !prAdapter->fgEnable5GBand)) {
545             continue;
546         }
547
548         if (eSpecificBand == BAND_NULL || prSubband->ucBand == eSpecificBand) {
549             for (j = 0; j < prSubband->ucNumChannels; j++) {
550                 if (ucNum >= ucMaxChannelNum) {
551                     break;
552                 }
553                 paucChannelList[ucNum].eBand = prSubband->ucBand;
554                 paucChannelList[ucNum].ucChannelNum =
555                     prSubband->ucFirstChannelNum + j * prSubband->ucChannelSpan;
556                 ucNum++;
557             }
558         }
559     }
560
561     *pucNumOfChannel = ucNum;
562 }
563
564 /*----------------------------------------------------------------------------*/
565 /*!
566 * @brief
567 *
568 * @param[in]
569 *
570 * @return (none)
571 */
572 /*----------------------------------------------------------------------------*/
573 VOID
574 rlmDomainSendCmd (
575     P_ADAPTER_T     prAdapter,
576     BOOLEAN         fgIsOid
577     )
578 {
579     P_DOMAIN_INFO_ENTRY     prDomainInfo;
580     P_CMD_SET_DOMAIN_INFO_T prCmd;
581     WLAN_STATUS             rStatus;
582     UINT_8                  i;
583     P_DOMAIN_SUBBAND_INFO   prSubBand;
584
585     prDomainInfo = rlmDomainGetDomainInfo(prAdapter);
586     ASSERT(prDomainInfo);
587
588     prCmd = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(CMD_SET_DOMAIN_INFO_T));
589     ASSERT(prCmd);
590
591     /* To do: exception handle */
592     if (!prCmd) {
593         DBGLOG(RLM, ERROR, ("Domain: no buf to send cmd\n"));
594         return;
595     }
596     kalMemZero(prCmd, sizeof(CMD_SET_DOMAIN_INFO_T));
597
598     prCmd->u2CountryCode = prAdapter->rWifiVar.rConnSettings.u2CountryCode;
599     prCmd->u2Reserved = 0;
600     prCmd->uc2G4Bandwidth =
601             prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode;
602     prCmd->uc5GBandwidth =
603             prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode;
604
605     for (i = 0; i < 6; i++) {
606         prSubBand = &prDomainInfo->rSubBand[i];
607
608         prCmd->rSubBand[i].ucRegClass = prSubBand->ucRegClass;
609         prCmd->rSubBand[i].ucBand = prSubBand->ucBand;
610
611         if (prSubBand->ucBand != BAND_NULL && prSubBand->ucBand < BAND_NUM) {
612             prCmd->rSubBand[i].ucChannelSpan = prSubBand->ucChannelSpan;
613             prCmd->rSubBand[i].ucFirstChannelNum = prSubBand->ucFirstChannelNum;
614             prCmd->rSubBand[i].ucNumChannels = prSubBand->ucNumChannels;
615         }
616     }
617
618     /* Update domain info to chip */
619     rStatus = wlanSendSetQueryCmd (
620                 prAdapter,                  /* prAdapter */
621                 CMD_ID_SET_DOMAIN_INFO,     /* ucCID */
622                 TRUE,                       /* fgSetQuery */
623                 FALSE,                      /* fgNeedResp */
624                 fgIsOid,                    /* fgIsOid */
625                 NULL,                       /* pfCmdDoneHandler*/
626                 NULL,                       /* pfCmdTimeoutHandler */
627                 sizeof(CMD_SET_DOMAIN_INFO_T),    /* u4SetQueryInfoLen */
628                 (PUINT_8) prCmd,            /* pucInfoBuffer */
629                 NULL,                       /* pvSetQueryBuffer */
630                 0                           /* u4SetQueryBufferLen */
631                 );
632
633     ASSERT(rStatus == WLAN_STATUS_PENDING);
634
635     cnmMemFree(prAdapter, prCmd);
636 }
637
638 /*----------------------------------------------------------------------------*/
639 /*!
640 * \brief
641 *
642 * \param[in/out]
643 *
644 * \return TRUE  Legal channel
645 *         FALSE Illegal channel for current regulatory domain
646 */
647 /*----------------------------------------------------------------------------*/
648 BOOLEAN
649 rlmDomainIsLegalChannel (
650     P_ADAPTER_T     prAdapter,
651     ENUM_BAND_T     eBand,
652     UINT_8          ucChannel
653     )
654 {
655     UINT_8                  i, j;
656     P_DOMAIN_SUBBAND_INFO   prSubband;
657     P_DOMAIN_INFO_ENTRY     prDomainInfo;
658
659     prDomainInfo = rlmDomainGetDomainInfo(prAdapter);
660     ASSERT(prDomainInfo);
661
662     for (i = 0; i < MAX_SUBBAND_NUM; i++) {
663         prSubband = &prDomainInfo->rSubBand[i];
664
665         if (prSubband->ucBand == BAND_5G && !prAdapter->fgEnable5GBand) {
666             continue;
667         }
668
669         if (prSubband->ucBand == eBand) {
670             for (j = 0; j < prSubband->ucNumChannels; j++) {
671                 if ((prSubband->ucFirstChannelNum + j*prSubband->ucChannelSpan)
672                     == ucChannel) {
673                     return TRUE;
674                 }
675             }
676         }
677     }
678
679     return FALSE;
680 }
681