1 /*
2 * Copyright (c) 2011,2013-2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /*
21 * Notifications and licenses are retained for attribution purposes only.
22 */
23 /*
24 * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting
25 * Copyright (c) 2005-2006 Atheros Communications, Inc.
26 * Copyright (c) 2010, Atheros Communications Inc.
27 *
28 * Redistribution and use in source and binary forms are permitted
29 * provided that the following conditions are met:
30 * 1. The materials contained herein are unmodified and are used
31 * unmodified.
32 * 2. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following NO
34 * ''WARRANTY'' disclaimer below (''Disclaimer''), without
35 * modification.
36 * 3. Redistributions in binary form must reproduce at minimum a
37 * disclaimer similar to the Disclaimer below and any redistribution
38 * must be conditioned upon including a substantially similar
39 * Disclaimer requirement for further binary redistribution.
40 * 4. Neither the names of the above-listed copyright holders nor the
41 * names of any contributors may be used to endorse or promote
42 * product derived from this software without specific prior written
43 * permission.
44 *
45 * NO WARRANTY
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 * ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT,
49 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
51 * FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
53 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
54 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
56 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGES.
58 */
59
60 #include "qdf_types.h"
61 #include "wma.h"
62 #include "cds_regdomain.h"
63
64
65 static const struct reg_dmn_pair g_reg_dmn_pairs[] = {
66 {NO_ENUMRD, FCC8, FCCA, CTRY_DEFAULT},
67 {NULL1_WORLD, NULL1, WORLD, CTRY_DEFAULT},
68 {FCC1_FCCA, FCC1, FCCA, CTRY_DEFAULT},
69 {FCC1_WORLD, FCC1, WORLD, CTRY_DEFAULT},
70 {FCC2_WORLD, FCC2, WORLD, CTRY_DEFAULT},
71 {FCC2_ETSIC, FCC2, ETSIC, CTRY_DEFAULT},
72 {FCC2_FCCA, FCC2, FCCA, CTRY_DEFAULT},
73 {FCC3_FCCA, FCC3, FCCA, CTRY_DEFAULT},
74 {FCC3_WORLD, FCC3, WORLD, CTRY_DEFAULT},
75 {FCC3_ETSIC, FCC3, ETSIC, CTRY_DEFAULT},
76 {FCC4_FCCA, FCC4, FCCA, CTRY_DEFAULT},
77 {FCC5_FCCA, FCC5, FCCA, CTRY_DEFAULT},
78 {FCC6_FCCA, FCC6, FCCA, CTRY_DEFAULT},
79 {FCC7_FCCA, FCC7, FCCA, CTRY_DEFAULT},
80 {FCC8_FCCA, FCC8, FCCA, CTRY_DEFAULT},
81 {FCC6_WORLD, FCC6, WORLD, CTRY_DEFAULT},
82 {FCC9_FCCA, FCC9, FCCA, CTRY_DEFAULT},
83 {FCC10_FCCA, FCC10, FCCA, CTRY_DEFAULT},
84 {FCC11_WORLD, FCC11, WORLD, CTRY_DEFAULT},
85 {FCC13_WORLD, FCC13, WORLD, CTRY_DEFAULT},
86 {FCC14_FCCB, FCC14, FCCB, CTRY_DEFAULT},
87 {ETSI1_WORLD, ETSI1, WORLD, CTRY_DEFAULT},
88 {ETSI3_WORLD, ETSI3, WORLD, CTRY_DEFAULT},
89 {ETSI4_WORLD, ETSI4, WORLD, CTRY_DEFAULT},
90 {ETSI7_WORLD, ETSI4, WORLD, CTRY_DEFAULT},
91 {ETSI8_WORLD, ETSI8, WORLD, CTRY_DEFAULT},
92 {ETSI9_WORLD, ETSI9, WORLD, CTRY_DEFAULT},
93 {APL4_WORLD, APL4, WORLD, CTRY_DEFAULT},
94 {APL2_WORLD, APL2, WORLD, CTRY_DEFAULT},
95 {APL2_FCCA, APL2, FCCA, CTRY_DEFAULT},
96 {APL2_ETSIC, APL2, ETSIC, CTRY_DEFAULT},
97 {APL1_WORLD, APL1, WORLD, CTRY_DEFAULT},
98 {APL1_ETSIC, APL1, ETSIC, CTRY_DEFAULT},
99 {APL6_WORLD, APL6, WORLD, CTRY_DEFAULT},
100 {APL7_FCCA, APL7, FCCA, CTRY_DEFAULT},
101 {APL8_WORLD, APL8, WORLD, CTRY_DEFAULT},
102 {APL9_WORLD, APL9, WORLD, CTRY_DEFAULT},
103 {APL10_WORLD, APL10, WORLD, CTRY_DEFAULT},
104 {APL12_WORLD, APL12, WORLD, CTRY_DEFAULT},
105 {APL13_WORLD, APL13, WORLD, CTRY_DEFAULT},
106 {APL14_WORLD, APL14, WORLD, CTRY_DEFAULT},
107 {APL15_WORLD, APL15, WORLD, CTRY_DEFAULT},
108 {APL16_WORLD, APL16, WORLD, CTRY_DEFAULT},
109 {APL17_ETSID, APL17, WORLD, CTRY_DEFAULT},
110 {APL20_WORLD, APL20, WORLD, CTRY_DEFAULT},
111 {APL23_WORLD, APL23, WORLD, CTRY_DEFAULT},
112 {WOR0_WORLD, WOR0_WORLD, WOR0_WORLD, CTRY_DEFAULT},
113 {WOR1_WORLD, WOR1_WORLD, WOR1_WORLD, CTRY_DEFAULT},
114 {WOR2_WORLD, WOR2_WORLD, WOR2_WORLD, CTRY_DEFAULT},
115 {WOR3_WORLD, WOR3_WORLD, WOR3_WORLD, CTRY_DEFAULT},
116 {WOR4_FCCA, WOR4_FCCA, WOR4_FCCA, CTRY_DEFAULT},
117 {WOR5_ETSIC, WOR5_ETSIC, WOR5_ETSIC, CTRY_DEFAULT},
118 {WOR01_WORLD, WOR01_WORLD, WOR01_WORLD, CTRY_DEFAULT},
119 {WOR02_WORLD, WOR02_WORLD, WOR02_WORLD, CTRY_DEFAULT},
120 {EU1_WORLD, EU1_WORLD, EU1_WORLD, CTRY_DEFAULT},
121 {WOR9_WORLD, WOR9_WORLD, WOR9_WORLD, CTRY_DEFAULT},
122 {WORA_WORLD, WORA_WORLD, WORA_WORLD, CTRY_DEFAULT},
123 {WORB_WORLD, WORB_WORLD, WORB_WORLD, CTRY_DEFAULT},
124 {WORC_WORLD, WORC_WORLD, WORC_WORLD, CTRY_DEFAULT},
125 {MKK5_MKKC, MKK5, MKKC, CTRY_JAPAN15},
126 {MKK5_MKKA2, MKK5, MKKA, CTRY_DEFAULT},
127 };
128
129 static const struct country_code_to_reg_dmn g_all_countries[] = {
130 {CTRY_AFGHANISTAN, ETSI1_WORLD, "AF", "AFGHANISTAN"},
131 {CTRY_ALBANIA, ETSI1_WORLD, "AL", "ALBANIA"},
132 {CTRY_ALGERIA, APL13_WORLD, "DZ", "ALGERIA"},
133 {CTRY_AMERICAN_SAMOA, FCC3_FCCA, "AS", "AMERICAN SAMOA"},
134 {CTRY_ANGUILLA, ETSI1_WORLD, "AI", "ANGUILLA"},
135 {CTRY_ARGENTINA, APL17_ETSID, "AR", "ARGENTINA"},
136 {CTRY_ARMENIA, ETSI4_WORLD, "AM", "ARMENIA"},
137 {CTRY_ARUBA, ETSI1_WORLD, "AW", "ARUBA"},
138 {CTRY_AUSTRALIA, FCC6_WORLD, "AU", "AUSTRALIA"},
139 {CTRY_AUSTRIA, ETSI1_WORLD, "AT", "AUSTRIA"},
140 {CTRY_AZERBAIJAN, ETSI4_WORLD, "AZ", "AZERBAIJAN"},
141 {CTRY_BAHAMAS, FCC3_WORLD, "BS", "BAHAMAS"},
142 {CTRY_BAHRAIN, APL15_WORLD, "BH", "BAHRAIN"},
143 {CTRY_BANGLADESH, APL1_WORLD, "BD", "BANGLADESH"},
144 {CTRY_BARBADOS, FCC2_WORLD, "BB", "BARBADOS"},
145 {CTRY_BELARUS, ETSI1_WORLD, "BY", "BELARUS"},
146 {CTRY_BELGIUM, ETSI1_WORLD, "BE", "BELGIUM"},
147 {CTRY_BELIZE, ETSI8_WORLD, "BZ", "BELIZE"},
148 {CTRY_BERMUDA, FCC3_FCCA, "BM", "BERMUDA"},
149 {CTRY_BHUTAN, ETSI1_WORLD, "BT", "BHUTAN"},
150 {CTRY_BOLIVIA, APL8_WORLD, "BO", "BOLIVIA"},
151 {CTRY_BOSNIA_HERZ, ETSI1_WORLD, "BA", "BOSNIA AND HERZEGOVINA"},
152 {CTRY_BRAZIL, FCC3_ETSIC, "BR", "BRAZIL"},
153 {CTRY_BRUNEI_DARUSSALAM, APL6_WORLD, "BN", "BRUNEI DARUSSALAM"},
154 {CTRY_BULGARIA, ETSI1_WORLD, "BG", "BULGARIA"},
155 {CTRY_BURKINA_FASO, FCC3_WORLD, "BF", "BURKINA-FASO"},
156 {CTRY_CAMBODIA, ETSI1_WORLD, "KH", "CAMBODIA"},
157 {CTRY_CANADA, FCC3_FCCA, "CA", "CANADA"},
158 {CTRY_CAYMAN_ISLANDS, FCC3_WORLD, "KY", "CAYMAN ISLANDS"},
159 {CTRY_CENTRAL_AFRICA_REPUBLIC, FCC3_WORLD, "CF", "AFRICA REPUBLIC"},
160 {CTRY_CHAD, ETSI1_WORLD, "TD", "CHAD"},
161 {CTRY_CHILE, APL23_WORLD, "CL", "CHILE"},
162 {CTRY_CHINA, APL14_WORLD, "CN", "CHINA"},
163 {CTRY_CHRISTMAS_ISLAND, FCC3_WORLD, "CX", "CHRISTMAS ISLAND"},
164 {CTRY_COLOMBIA, FCC3_WORLD, "CO", "COLOMBIA"},
165 {CTRY_COSTA_RICA, FCC3_WORLD, "CR", "COSTA RICA"},
166 {CTRY_COTE_DIVOIRE, FCC3_WORLD, "CI", "COTE DIVOIRE"},
167 {CTRY_CROATIA, ETSI1_WORLD, "HR", "CROATIA"},
168 {CTRY_CYPRUS, ETSI1_WORLD, "CY", "CYPRUS"},
169 {CTRY_CZECH, ETSI1_WORLD, "CZ", "CZECH REPUBLIC"},
170 {CTRY_DENMARK, ETSI1_WORLD, "DK", "DENMARK"},
171 {CTRY_DOMINICA, FCC2_FCCA, "DM", "DOMINICA"},
172 {CTRY_DOMINICAN_REPUBLIC, FCC2_FCCA, "DO", "DOMINICAN REPUBLIC"},
173 {CTRY_ECUADOR, FCC3_WORLD, "EC", "ECUADOR"},
174 {CTRY_EGYPT, ETSI3_WORLD, "EG", "EGYPT"},
175 {CTRY_EL_SALVADOR, FCC2_WORLD, "SV", "EL SALVADOR"},
176 {CTRY_ESTONIA, ETSI1_WORLD, "EE", "ESTONIA"},
177 {CTRY_ETHIOPIA, ETSI1_WORLD, "ET", "ETHIOPIA"},
178 {CTRY_FINLAND, ETSI1_WORLD, "FI", "FINLAND"},
179 {CTRY_FRANCE, ETSI1_WORLD, "FR", "FRANCE"},
180 {CTRY_FRENCH_GUIANA, ETSI1_WORLD, "GF", "FRENCH GUIANA"},
181 {CTRY_FRENCH_POLYNESIA, ETSI1_WORLD, "PF", "FRENCH POLYNESIA"},
182 {CTRY_GEORGIA, ETSI4_WORLD, "GE", "GEORGIA"},
183 {CTRY_GERMANY, ETSI1_WORLD, "DE", "GERMANY"},
184 {CTRY_GHANA, FCC3_WORLD, "GH", "GHANA"},
185 {CTRY_GIBRALTAR, ETSI1_WORLD, "GI", "GIBRALTAR"},
186 {CTRY_GREECE, ETSI1_WORLD, "GR", "GREECE"},
187 {CTRY_GREENLAND, ETSI1_WORLD, "GL", "GREENLAND"},
188 {CTRY_GRENADA, FCC3_FCCA, "GD", "GRENADA"},
189 {CTRY_GUADELOUPE, ETSI1_WORLD, "GP", "GUADELOUPE"},
190 {CTRY_GUAM, FCC3_FCCA, "GU", "GUAM"},
191 {CTRY_GUATEMALA, ETSI1_WORLD, "GT", "GUATEMALA"},
192 {CTRY_GUYANA, APL1_ETSIC, "GY", "GUYANA"},
193 {CTRY_HAITI, FCC3_FCCA, "HT", "HAITI"},
194 {CTRY_HONDURAS, FCC13_WORLD, "HN", "HONDURAS"},
195 {CTRY_HONG_KONG, FCC3_WORLD, "HK", "HONG KONG"},
196 {CTRY_HUNGARY, ETSI1_WORLD, "HU", "HUNGARY"},
197 {CTRY_ICELAND, ETSI1_WORLD, "IS", "ICELAND"},
198 {CTRY_INDIA, APL15_WORLD, "IN", "INDIA"},
199 {CTRY_INDONESIA, APL2_ETSIC, "ID", "INDONESIA"},
200 {CTRY_IRAQ, ETSI1_WORLD, "IQ", "IRAQ"},
201 {CTRY_IRELAND, ETSI1_WORLD, "IE", "IRELAND"},
202 {CTRY_ISRAEL, ETSI3_WORLD, "IL", "ISRAEL"},
203 {CTRY_ITALY, ETSI1_WORLD, "IT", "ITALY"},
204 {CTRY_JAMAICA, FCC13_WORLD, "JM", "JAMAICA"},
205 {CTRY_JORDAN, APL4_WORLD, "JO", "JORDAN"},
206 {CTRY_KAZAKHSTAN, NULL1_WORLD, "KZ", "KAZAKHSTAN"},
207 {CTRY_KENYA, APL12_WORLD, "KE", "KENYA"},
208 {CTRY_KOREA_ROC, APL9_WORLD, "KR", "KOREA REPUBLIC"},
209 {CTRY_KUWAIT, ETSI3_WORLD, "KW", "KUWAIT"},
210 {CTRY_LATVIA, ETSI1_WORLD, "LV", "LATVIA"},
211 {CTRY_LEBANON, FCC3_WORLD, "LB", "LEBANON"},
212 {CTRY_LESOTHO, ETSI1_WORLD, "LS", "LESOTHO"},
213 {CTRY_LIECHTENSTEIN, ETSI1_WORLD, "LI", "LIECHTENSTEIN"},
214 {CTRY_LITHUANIA, ETSI1_WORLD, "LT", "LITHUANIA"},
215 {CTRY_LUXEMBOURG, ETSI1_WORLD, "LU", "LUXEMBOURG"},
216 {CTRY_MACAU, FCC3_WORLD, "MO", "MACAU SAR"},
217 {CTRY_MACEDONIA, ETSI1_WORLD, "MK", "MACEDONIA, FYRO"},
218 {CTRY_MALAWI, ETSI1_WORLD, "MW", "MALAWI"},
219 {CTRY_MALAYSIA, FCC11_WORLD, "MY", "MALAYSIA"},
220 {CTRY_MALDIVES, APL6_WORLD, "MV", "MALDIVES"},
221 {CTRY_MALTA, ETSI1_WORLD, "MT", "MALTA"},
222 {CTRY_MARSHALL_ISLANDS, FCC3_FCCA, "MH", "MARSHALL ISLANDS"},
223 {CTRY_MARTINIQUE, ETSI1_WORLD, "MQ", "MARTINIQUE"},
224 {CTRY_MAURITANIA, ETSI1_WORLD, "MR", "MAURITANA"},
225 {CTRY_MAURITIUS, FCC3_WORLD, "MU", "MAURITIUS"},
226 {CTRY_MAYOTTE, ETSI1_WORLD, "YT", "MAYOTTE"},
227 {CTRY_MEXICO, FCC3_ETSIC, "MX", "MEXICO"},
228 {CTRY_MICRONESIA, FCC3_FCCA, "FM", "MICRONESIA"},
229 {CTRY_MOLDOVA, ETSI1_WORLD, "MD", "MOLDOVA"},
230 {CTRY_MONACO, ETSI1_WORLD, "MC", "MONACO"},
231 {CTRY_MONGOLIA, FCC3_WORLD, "MN", "MONGOLIA"},
232 {CTRY_MONTENEGRO, ETSI1_WORLD, "ME", "MONTENEGRO"},
233 {CTRY_MOROCCO, ETSI3_WORLD, "MA", "MOROCCO"},
234 {CTRY_NAMIBIA, APL20_WORLD, "NA", "NAMIBIA"},
235 {CTRY_NEPAL, APL23_WORLD, "NP", "NEPAL"},
236 {CTRY_NETHERLANDS, ETSI1_WORLD, "NL", "NETHERLANDS"},
237 {CTRY_NETHERLANDS_ANTILLES, ETSI1_WORLD, "AN", "NETHERLANDS ANTILLES"},
238 {CTRY_NEW_ZEALAND, FCC3_ETSIC, "NZ", "NEW ZEALAND"},
239 {CTRY_NIGERIA, APL8_WORLD, "NG", "NIGERIA"},
240 {CTRY_NORTHERN_MARIANA_ISLANDS, FCC3_FCCA, "MP", "MARIANA ISLANDS"},
241 {CTRY_NICARAGUA, FCC3_FCCA, "NI", "NICARAGUA"},
242 {CTRY_NORWAY, ETSI1_WORLD, "NO", "NORWAY"},
243 {CTRY_OMAN, ETSI1_WORLD, "OM", "OMAN"},
244 {CTRY_PAKISTAN, APL1_ETSIC, "PK", "PAKISTAN"},
245 {CTRY_PALAU, FCC3_FCCA, "PW", "PALAU"},
246 {CTRY_PANAMA, FCC14_FCCB, "PA", "PANAMA"},
247 {CTRY_PAPUA_NEW_GUINEA, FCC3_WORLD, "PG", "PAPUA NEW GUINEA"},
248 {CTRY_PARAGUAY, FCC3_WORLD, "PY", "PARAGUAY"},
249 {CTRY_PERU, FCC3_WORLD, "PE", "PERU"},
250 {CTRY_PHILIPPINES, FCC3_WORLD, "PH", "PHILIPPINES"},
251 {CTRY_POLAND, ETSI1_WORLD, "PL", "POLAND"},
252 {CTRY_PORTUGAL, ETSI1_WORLD, "PT", "PORTUGAL"},
253 {CTRY_PUERTO_RICO, FCC3_FCCA, "PR", "PUERTO RICO"},
254 {CTRY_QATAR, APL1_WORLD, "QA", "QATAR"},
255 {CTRY_REUNION, ETSI1_WORLD, "RE", "REUNION"},
256 {CTRY_ROMANIA, ETSI1_WORLD, "RO", "ROMANIA"},
257 {CTRY_RUSSIA, ETSI8_WORLD, "RU", "RUSSIA"},
258 {CTRY_RWANDA, FCC3_WORLD, "RW", "RWANDA"},
259 {CTRY_SAINT_BARTHELEMY, ETSI1_WORLD, "BL", "SAINT BARTHELEMY"},
260 {CTRY_SAINT_KITTS_AND_NEVIS, APL10_WORLD, "KN", "SAINT KITTS"},
261 {CTRY_SAINT_LUCIA, APL10_WORLD, "LC", "SAINT LUCIA"},
262 {CTRY_SAINT_MARTIN, ETSI1_WORLD, "MF", "SAINT MARTIN"},
263 {CTRY_SAINT_PIERRE_AND_MIQUELON, ETSI1_WORLD, "PM", "SAINT PIERRE"},
264 {CTRY_SAINT_VINCENT_AND_THE_GRENADIENS, ETSI1_WORLD, "VC", "VINCENT"},
265 {CTRY_SAMOA, ETSI1_WORLD, "WS", "SAMOA"},
266 {CTRY_SAUDI_ARABIA, ETSI1_WORLD, "SA", "SAUDI ARABIA"},
267 {CTRY_SENEGAL, FCC13_WORLD, "SN", "SENEGAL"},
268 {CTRY_SERBIA, ETSI1_WORLD, "RS", "REPUBLIC OF SERBIA"},
269 {CTRY_SINGAPORE, FCC3_WORLD, "SG", "SINGAPORE"},
270 {CTRY_SLOVAKIA, ETSI1_WORLD, "SK", "SLOVAKIA"},
271 {CTRY_SLOVENIA, ETSI1_WORLD, "SI", "SLOVENIA"},
272 {CTRY_SOUTH_AFRICA, FCC3_WORLD, "ZA", "SOUTH AFRICA"},
273 {CTRY_SPAIN, ETSI1_WORLD, "ES", "SPAIN"},
274 {CTRY_SURINAME, ETSI1_WORLD, "SR", "SURINAME"},
275 {CTRY_SRI_LANKA, FCC3_WORLD, "LK", "SRI LANKA"},
276 {CTRY_SWEDEN, ETSI1_WORLD, "SE", "SWEDEN"},
277 {CTRY_SWITZERLAND, ETSI1_WORLD, "CH", "SWITZERLAND"},
278 {CTRY_TAIWAN, FCC3_FCCA, "TW", "TAIWAN"},
279 {CTRY_TANZANIA, APL1_WORLD, "TZ", "TANZANIA"},
280 {CTRY_THAILAND, FCC3_WORLD, "TH", "THAILAND"},
281 {CTRY_TOGO, ETSI1_WORLD, "TG", "TOGO"},
282 {CTRY_TRINIDAD_Y_TOBAGO, FCC3_WORLD, "TT", "TRINIDAD AND TOBAGO"},
283 {CTRY_TUNISIA, ETSI3_WORLD, "TN", "TUNISIA"},
284 {CTRY_TURKEY, ETSI1_WORLD, "TR", "TURKEY"},
285 {CTRY_TURKS_AND_CAICOS, FCC3_WORLD, "TC" "TURKS AND CAICOS"},
286 {CTRY_UGANDA, FCC3_WORLD, "UG", "UGANDA"},
287 {CTRY_UKRAINE, ETSI9_WORLD, "UA", "UKRAINE"},
288 {CTRY_UAE, FCC3_WORLD, "AE", "UNITED ARAB EMIRATES"},
289 {CTRY_UNITED_KINGDOM, ETSI1_WORLD, "GB", "UNITED KINGDOM"},
290 {CTRY_UNITED_STATES, FCC8_FCCA, "US", "UNITED STATES"},
291 {CTRY_URUGUAY, FCC2_WORLD, "UY", "URUGUAY"},
292 {CTRY_UZBEKISTAN, ETSI3_WORLD, "UZ", "UZBEKISTAN"},
293 {CTRY_VANUATU, FCC3_WORLD, "VU", "VANUATU"},
294 {CTRY_VENEZUELA, FCC2_ETSIC, "VE", "VENEZUELA"},
295 {CTRY_VIET_NAM, FCC3_WORLD, "VN", "VIETNAM"},
296 {CTRY_VIRGIN_ISLANDS, FCC3_FCCA, "VI", "VIRGIN ISLANDS"},
297 {CTRY_WALLIS_AND_FUTUNA, ETSI1_WORLD, "WF" "WALLIS"},
298 {CTRY_YEMEN, NULL1_WORLD, "YE", "YEMEN"},
299 {CTRY_ZIMBABWE, ETSI1_WORLD, "ZW", "ZIMBABWE"},
300 {CTRY_JAPAN15, MKK5_MKKC, "JP", "JAPAN"},
301 {CTRY_XA, MKK5_MKKA2, "XA", "JAPAN PASSIVE"}
302 };
303
304 static const struct reg_dmn g_reg_dmns[] = {
305 {FCC1, CTL_FCC},
306 {FCC2, CTL_FCC},
307 {FCC3, CTL_FCC},
308 {FCC4, CTL_FCC},
309 {FCC5, CTL_FCC},
310 {FCC6, CTL_FCC},
311 {FCC7, CTL_FCC},
312 {FCC8, CTL_FCC},
313 {FCC9, CTL_FCC},
314 {FCC10, CTL_FCC},
315 {FCC11, CTL_FCC},
316 {FCC13, CTL_FCC},
317 {FCC14, CTL_FCC},
318 {ETSI1, CTL_ETSI},
319 {ETSI2, CTL_ETSI},
320 {ETSI3, CTL_ETSI},
321 {ETSI4, CTL_ETSI},
322 {ETSI5, CTL_ETSI},
323 {ETSI6, CTL_ETSI},
324 {ETSI8, CTL_ETSI},
325 {ETSI9, CTL_ETSI},
326 {ETSI10, CTL_ETSI},
327 {ETSI11, CTL_ETSI},
328 {APL1, CTL_ETSI},
329 {APL2, CTL_ETSI},
330 {APL3, CTL_ETSI},
331 {APL4, CTL_ETSI},
332 {APL5, CTL_ETSI},
333 {APL6, CTL_ETSI},
334 {APL7, CTL_ETSI},
335 {APL8, CTL_ETSI},
336 {APL9, CTL_ETSI},
337 {APL10, CTL_ETSI},
338 {APL11, CTL_ETSI},
339 {APL12, CTL_ETSI},
340 {APL13, CTL_ETSI},
341 {APL14, CTL_FCC},
342 {APL15, CTL_FCC},
343 {APL16, CTL_FCC},
344 {APL17, CTL_FCC},
345 {APL20, CTL_ETSI},
346 {APL23, CTL_ETSI},
347 {NULL1, CTL_NONE},
348 {MKK3, CTL_MKK},
349 {MKK5, CTL_MKK},
350 {MKK11, CTL_MKK},
351 {WORLD, CTL_ETSI},
352 {FCCA, CTL_FCC},
353 {MKKA, CTL_MKK},
354 {MKKC, CTL_MKK},
355 {ETSIC, CTL_ETSI},
356 {WOR0_WORLD, CTL_NONE},
357 {WOR1_WORLD, CTL_NONE},
358 {WOR2_WORLD, CTL_NONE},
359 {WOR3_WORLD, CTL_NONE},
360 {WOR4_FCCA, CTL_NONE},
361 {WOR5_ETSIC, CTL_NONE},
362 {WOR01_WORLD, CTL_NONE},
363 {WOR02_WORLD, CTL_NONE},
364 {EU1_WORLD, CTL_NONE},
365 {WOR9_WORLD, CTL_NONE},
366 {WORA_WORLD, CTL_NONE},
367 {WORB_WORLD, CTL_NONE},
368 {WORC_WORLD, CTL_NONE},
369 };
370
371
372 struct reg_dmn_tables g_reg_dmn_tbl = {
373 g_reg_dmn_pairs,
374 g_all_countries,
375 g_reg_dmns,
376 QDF_ARRAY_SIZE(g_reg_dmn_pairs),
377 QDF_ARRAY_SIZE(g_all_countries),
378 QDF_ARRAY_SIZE(g_reg_dmns),
379 };
380
381 /*
382 * ETSI is updating EN 301 893, which specifies 5 GHz channel access
383 * in Europe
384 */
385 static const char etsi_europe_country[][2] = {
386 {'A', 'T'},
387 {'B', 'E'},
388 {'B', 'G'},
389 {'C', 'Z'},
390 {'D', 'K'},
391 {'E', 'E'},
392 {'F', 'R'},
393
394 {'D', 'E'},
395 {'I', 'S'},
396 {'I', 'E'},
397 {'I', 'T'},
398 {'E', 'L'},
399 {'E', 'S'},
400 {'C', 'Y'},
401
402 {'L', 'V'},
403 {'L', 'I'},
404 {'L', 'T'},
405 {'L', 'U'},
406 {'H', 'U'},
407 {'M', 'T'},
408 {'N', 'L'},
409
410 {'N', 'O'},
411 {'P', 'L'},
412 {'P', 'T'},
413 {'R', 'O'},
414 {'S', 'I'},
415 {'S', 'K'},
416 {'T', 'R'},
417
418 {'F', 'I'},
419 {'S', 'E'},
420 {'C', 'H'},
421 {'U', 'K'},
422 {'H', 'R'},
423 };
424
cds_is_etsi_europe_country(uint8_t * country)425 bool cds_is_etsi_europe_country(uint8_t *country)
426 {
427 int32_t i;
428
429 for (i = 0; i < QDF_ARRAY_SIZE(etsi_europe_country); i++) {
430 if (country[0] == etsi_europe_country[i][0] &&
431 country[1] == etsi_europe_country[i][1])
432 return true;
433 }
434
435 return false;
436 }
437
438 /**
439 * get_bdf_reg_dmn() - get regulatory domain from BDF
440 * @reg_dmn: BDF regulatory domain
441 *
442 * Return: regulatory domain
443 */
get_bdf_reg_dmn(uint16_t reg_dmn)444 static uint16_t get_bdf_reg_dmn(uint16_t reg_dmn)
445 {
446 return reg_dmn & ~WORLD_ROAMING_FLAG;
447 }
448
449 /**
450 * is_reg_dmn_valid() - is regulatory domain valid
451 * @reg_dmn: regulatory domain
452 *
453 * Return: true or false
454 */
is_reg_dmn_valid(uint16_t reg_dmn)455 static bool is_reg_dmn_valid(uint16_t reg_dmn)
456 {
457 int32_t i;
458
459 if (reg_dmn & CTRY_FLAG) {
460 uint16_t cc = reg_dmn & ~CTRY_FLAG;
461
462 for (i = 0; i < g_reg_dmn_tbl.all_countries_cnt; i++)
463 if (g_reg_dmn_tbl.all_countries[i].country_code == cc)
464 return true;
465 } else {
466 for (i = 0; i < g_reg_dmn_tbl.reg_dmn_pairs_cnt; i++)
467 if (g_reg_dmn_tbl.reg_dmn_pairs[i].reg_dmn_pair
468 == reg_dmn)
469 return true;
470 }
471
472 cds_err("invalid regulatory domain/country code 0x%x", reg_dmn);
473
474 return false;
475 }
476
477 /**
478 * find_country() - find country data
479 * @country_code: country code
480 *
481 * Return: country code data pointer
482 */
find_country(uint16_t country_code)483 static const struct country_code_to_reg_dmn *find_country(uint16_t country_code)
484 {
485 int32_t i;
486
487 for (i = 0; i < g_reg_dmn_tbl.all_countries_cnt; i++) {
488 if (g_reg_dmn_tbl.all_countries[i].country_code == country_code)
489 return &g_reg_dmn_tbl.all_countries[i];
490 }
491
492 return NULL;
493 }
494
495 /**
496 * cds_get_country_from_alpha2() - get country from alpha2
497 * @alpha2: country code alpha2
498 *
499 * Return: country code
500 */
cds_get_country_from_alpha2(uint8_t * alpha2)501 int32_t cds_get_country_from_alpha2(uint8_t *alpha2)
502 {
503 int32_t i;
504
505 for (i = 0; i < g_reg_dmn_tbl.all_countries_cnt; i++) {
506 if (g_reg_dmn_tbl.all_countries[i].alpha2[0] == alpha2[0] &&
507 g_reg_dmn_tbl.all_countries[i].alpha2[1] == alpha2[1])
508 return g_reg_dmn_tbl.all_countries[i].country_code;
509 }
510
511 return CTRY_DEFAULT;
512 }
513
514 /**
515 * reg_dmn_get_default_country() - get default country for regulatory domain
516 * @reg_dmn: regulatory domain
517 *
518 * Return: default country
519 */
reg_dmn_get_default_country(uint16_t reg_dmn)520 static uint16_t reg_dmn_get_default_country(uint16_t reg_dmn)
521 {
522 int32_t i;
523 const struct country_code_to_reg_dmn *country = NULL;
524 uint16_t cc = reg_dmn & ~CTRY_FLAG;
525
526 if (reg_dmn & CTRY_FLAG) {
527 country = find_country(cc);
528 if (country)
529 return cc;
530 }
531
532 for (i = 0; i < g_reg_dmn_tbl.reg_dmn_pairs_cnt; i++) {
533 if (g_reg_dmn_tbl.reg_dmn_pairs[i].reg_dmn_pair == reg_dmn) {
534 if (g_reg_dmn_tbl.reg_dmn_pairs[i].single_cc != 0)
535 return g_reg_dmn_tbl.reg_dmn_pairs[i].single_cc;
536 else
537 i = g_reg_dmn_tbl.reg_dmn_pairs_cnt;
538 }
539 }
540
541 return CTRY_DEFAULT;
542 }
543
544 /**
545 * get_reg_dmn_pair() - get regulatory domain pair pointer
546 * @reg_dmn: regulatory domain
547 *
548 * Return: pointer to regulatory domain pair data
549 */
get_reg_dmn_pair(uint16_t reg_dmn)550 static const struct reg_dmn_pair *get_reg_dmn_pair(uint16_t reg_dmn)
551 {
552 int32_t i;
553
554 for (i = 0; i < g_reg_dmn_tbl.reg_dmn_pairs_cnt; i++) {
555 if (g_reg_dmn_tbl.reg_dmn_pairs[i].reg_dmn_pair == reg_dmn)
556 return &g_reg_dmn_tbl.reg_dmn_pairs[i];
557 }
558
559 return NULL;
560 }
561
562 /**
563 * get_reg_dmn() - get regulatory domain pointer
564 * @reg_dmn: regulatory domain
565 *
566 * Return: pointer to regulatory domain data
567 */
get_reg_dmn(uint16_t reg_dmn)568 static const struct reg_dmn *get_reg_dmn(uint16_t reg_dmn)
569 {
570 int32_t i;
571
572 for (i = 0; i < g_reg_dmn_tbl.reg_dmns_cnt; i++) {
573 if (g_reg_dmn_tbl.reg_dmns[i].reg_dmn == reg_dmn)
574 return &g_reg_dmn_tbl.reg_dmns[i];
575 }
576
577 return NULL;
578 }
579
580 /**
581 * get_country_from_rd() - get country from regulatory domain
582 * @reg_dmn: regulatory domain
583 *
584 * Return: country code enum
585 */
get_country_from_rd(uint16_t reg_dmn)586 static const struct country_code_to_reg_dmn *get_country_from_rd(
587 uint16_t reg_dmn)
588 {
589 int32_t i;
590
591 for (i = 0; i < g_reg_dmn_tbl.all_countries_cnt; i++) {
592 if (g_reg_dmn_tbl.all_countries[i].reg_dmn_pair == reg_dmn)
593 return &g_reg_dmn_tbl.all_countries[i];
594 }
595
596 return NULL;
597 }
598
599 /**
600 * reg_dmn_sanitize() - sanitize regulatory domain
601 * @reg: regulatory data structure
602 *
603 * Return: none
604 */
reg_dmn_sanitize(struct regulatory * reg)605 static void reg_dmn_sanitize(struct regulatory *reg)
606 {
607 if (reg->reg_domain != CTRY_FLAG)
608 return;
609
610 reg->reg_domain = WOR0_WORLD;
611 }
612
613 /**
614 * cds_fill_some_regulatory_info() - fill regulatory information
615 * @reg: regulatory data structure
616 *
617 * Return: error code
618 */
cds_fill_some_regulatory_info(struct regulatory * reg)619 int32_t cds_fill_some_regulatory_info(struct regulatory *reg)
620 {
621 uint16_t country_code;
622 uint16_t reg_dmn, rd;
623 const struct country_code_to_reg_dmn *country = NULL;
624
625 reg_dmn_sanitize(reg);
626 rd = reg->reg_domain;
627
628 if (!is_reg_dmn_valid(rd))
629 return -EINVAL;
630
631 reg_dmn = get_bdf_reg_dmn(rd);
632
633 country_code = reg_dmn_get_default_country(reg_dmn);
634 if (country_code == CTRY_DEFAULT && reg_dmn == CTRY_DEFAULT)
635 country_code = CTRY_UNITED_STATES;
636
637 if (country_code != CTRY_DEFAULT) {
638 country = find_country(country_code);
639 if (!country) {
640 cds_err("not a valid country code");
641 return -EINVAL;
642 }
643
644 reg_dmn = country->reg_dmn_pair;
645 }
646
647 reg->regpair = get_reg_dmn_pair(reg_dmn);
648 if (!reg->regpair) {
649 cds_err("no regpair is found, can not proceed");
650 return -EINVAL;
651 }
652
653 reg->country_code = country_code;
654
655 if (!country)
656 country = get_country_from_rd(reg_dmn);
657
658 if (country) {
659 reg->alpha2[0] = country->alpha2[0];
660 reg->alpha2[1] = country->alpha2[1];
661 } else {
662 reg->alpha2[0] = '0';
663 reg->alpha2[1] = '0';
664 }
665
666 return 0;
667 }
668
669 /**
670 * cds_fill_and_send_ctl_to_fw() - fill and send ctl to firmware
671 * @reg: the regulatory handle
672 *
673 * Return: none
674 */
cds_fill_and_send_ctl_to_fw(struct regulatory * reg)675 void cds_fill_and_send_ctl_to_fw(struct regulatory *reg)
676 {
677 const struct reg_dmn *reg_dmn_2g = NULL;
678 const struct reg_dmn *reg_dmn_5g = NULL;
679 uint8_t ctl_2g, ctl_5g;
680 const struct reg_dmn_pair *regpair;
681 tp_wma_handle wma = cds_get_context(QDF_MODULE_ID_WMA);
682
683 if (!wma)
684 return;
685
686 if (!reg->regpair) {
687 cds_err(FL("no regpair is found, can not proceed"));
688 return;
689 }
690 regpair = reg->regpair;
691 reg_dmn_2g = get_reg_dmn(regpair->reg_dmn_2ghz);
692 if (!reg_dmn_2g) {
693 cds_err("failed to get regdmn 2G");
694 return;
695 }
696
697 reg_dmn_5g = get_reg_dmn(regpair->reg_dmn_5ghz);
698 if (!reg_dmn_5g) {
699 cds_err("failed to get regdmn 5G");
700 return;
701 }
702
703 ctl_2g = reg_dmn_2g->conformance_test_limit;
704 ctl_5g = reg_dmn_5g->conformance_test_limit;
705
706
707 reg->ctl_5g = ctl_5g;
708 reg->ctl_2g = ctl_2g;
709
710 wma_send_regdomain_info_to_fw(reg->reg_domain, regpair->reg_dmn_2ghz,
711 regpair->reg_dmn_5ghz, ctl_2g, ctl_5g);
712 }
713