2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
35 #include <net80211/_ieee80211.h>
36 #include <net80211/ieee80211_regdomain.h>
38 #include "ah_internal.h"
39 #include "ah_eeprom_v3.h" /* XXX */
48 int ath_hal_debug = 0;
49 HAL_CTRY_CODE cc = CTRY_DEFAULT;
50 HAL_REG_DOMAIN rd = 169; /* FCC */
54 HAL_BOOL HT20mode = 1;
55 HAL_BOOL HT40mode = 1;
56 HAL_BOOL turbo5Disable = AH_FALSE;
57 HAL_BOOL turbo2Disable = AH_FALSE;
59 u_int16_t _numCtls = 8;
61 { 0x10, 0x13, 0x40, 0x30, 0x11, 0x31, 0x12, 0x32 };
62 RD_EDGES_POWER _rdEdgesPower[NUM_EDGES*NUM_CTLS] = {
63 { 5180, 28, 0 }, /* 0x10 */
72 { 5210, 28, 0 }, /* 0x13 */
81 { 5170, 60, 0 }, /* 0x40 */
90 { 5180, 33, 0 }, /* 0x30 */
99 { 2412, 36, 0 }, /* 0x11 */
108 { 2412, 36, 0 }, /* 0x31 */
117 { 2412, 36, 0 }, /* 0x12 */
126 { 2412, 28, 0 }, /* 0x32 */
136 u_int16_t turbo2WMaxPower5 = 32;
137 u_int16_t turbo2WMaxPower2;
138 int8_t antennaGainMax[2] = { 0, 0 }; /* XXX */
139 int eeversion = AR_EEPROM_VER3_1;
140 TRGT_POWER_ALL_MODES tpow = {
142 { 22, 24, 28, 32, 5180 },
143 { 22, 24, 28, 32, 5200 },
144 { 22, 24, 28, 32, 5320 },
145 { 26, 30, 34, 34, 5500 },
146 { 26, 30, 34, 34, 5700 },
147 { 20, 30, 34, 36, 5745 },
148 { 20, 30, 34, 36, 5825 },
149 { 20, 30, 34, 36, 5850 },
152 { 23, 27, 31, 34, 2412 },
153 { 23, 27, 31, 34, 2447 },
156 { 36, 36, 36, 36, 2412 },
157 { 36, 36, 36, 36, 2484 },
160 #define numTargetPwr_11a tpow.numTargetPwr_11a
161 #define trgtPwr_11a tpow.trgtPwr_11a
162 #define numTargetPwr_11g tpow.numTargetPwr_11g
163 #define trgtPwr_11g tpow.trgtPwr_11g
164 #define numTargetPwr_11b tpow.numTargetPwr_11b
165 #define trgtPwr_11b tpow.trgtPwr_11b
168 getChannelEdges(struct ath_hal *ah, u_int16_t flags, u_int16_t *low, u_int16_t *high)
170 struct ath_hal_private *ahp = AH_PRIVATE(ah);
171 HAL_CAPABILITIES *pCap = &ahp->ah_caps;
173 if (flags & IEEE80211_CHAN_5GHZ) {
174 *low = pCap->halLow5GhzChan;
175 *high = pCap->halHigh5GhzChan;
178 if (flags & IEEE80211_CHAN_2GHZ) {
179 *low = pCap->halLow2GhzChan;
180 *high = pCap->halHigh2GhzChan;
187 getWirelessModes(struct ath_hal *ah)
194 mode |= HAL_MODE_TURBO;
197 mode |= HAL_MODE_11B;
199 mode |= HAL_MODE_11G;
201 mode |= HAL_MODE_108G;
204 mode |= HAL_MODE_11NG_HT20|HAL_MODE_11NA_HT20;
206 mode |= HAL_MODE_11NG_HT40PLUS|HAL_MODE_11NA_HT40PLUS
207 | HAL_MODE_11NG_HT40MINUS|HAL_MODE_11NA_HT40MINUS
212 /* Enumerated Regulatory Domain Information 8 bit values indicate that
213 * the regdomain is really a pair of unitary regdomains. 12 bit values
214 * are the real unitary regdomains and are the only ones which have the
215 * frequency bitmasks and flags set.
220 * The following regulatory domain definitions are
221 * found in the EEPROM. Each regulatory domain
222 * can operate in either a 5GHz or 2.4GHz wireless mode or
223 * both 5GHz and 2.4GHz wireless modes.
224 * In general, the value holds no special
225 * meaning and is used to decode into either specific
226 * 2.4GHz or 5GHz wireless mode for that particular
230 NULL1_WORLD = 0x03, /* For 11b-only countries (no 11a allowed) */
231 NULL1_ETSIB = 0x07, /* Israel */
233 FCC1_FCCA = 0x10, /* USA */
234 FCC1_WORLD = 0x11, /* Hong Kong */
235 FCC4_FCCA = 0x12, /* USA - Public Safety */
237 FCC2_FCCA = 0x20, /* Canada */
238 FCC2_WORLD = 0x21, /* Australia & HK */
240 FRANCE_RES = 0x31, /* Legacy France for OEM */
241 FCC3_FCCA = 0x3A, /* USA & Canada w/5470 band, 11h, DFS enabled */
242 FCC3_WORLD = 0x3B, /* USA & Canada w/5470 band, 11h, DFS enabled */
245 ETSI3_ETSIA = 0x32, /* France (optional) */
246 ETSI2_WORLD = 0x35, /* Hungary & others */
247 ETSI3_WORLD = 0x36, /* France & others */
251 ETSI6_WORLD = 0x34, /* Bulgaria */
252 ETSI_RESERVED = 0x33, /* Reserved (Do not used) */
254 MKK1_MKKA = 0x40, /* Japan (JP1) */
255 MKK1_MKKB = 0x41, /* Japan (JP0) */
256 APL4_WORLD = 0x42, /* Singapore */
257 MKK2_MKKA = 0x43, /* Japan with 4.9G channels */
258 APL_RESERVED = 0x44, /* Reserved (Do not used) */
259 APL2_WORLD = 0x45, /* Korea */
262 MKK1_FCCA = 0x48, /* Japan (JP1-1) */
263 APL2_APLD = 0x49, /* Korea with 2.3G channels */
264 MKK1_MKKA1 = 0x4A, /* Japan (JE1) */
265 MKK1_MKKA2 = 0x4B, /* Japan (JE2) */
266 MKK1_MKKC = 0x4C, /* Japan (MKK1_MKKA,except Ch14) */
269 APL1_WORLD = 0x52, /* Latin America */
273 APL2_ETSIC = 0x56, /* Venezuela */
274 APL5_WORLD = 0x58, /* Chile */
275 APL6_WORLD = 0x5B, /* Singapore */
276 APL7_FCCA = 0x5C, /* Taiwan 5.47 Band */
277 APL8_WORLD = 0x5D, /* Malaysia 5GHz */
278 APL9_WORLD = 0x5E, /* Korea 5GHz */
283 WOR0_WORLD = 0x60, /* World0 (WO0 SKU) */
284 WOR1_WORLD = 0x61, /* World1 (WO1 SKU) */
285 WOR2_WORLD = 0x62, /* World2 (WO2 SKU) */
286 WOR3_WORLD = 0x63, /* World3 (WO3 SKU) */
287 WOR4_WORLD = 0x64, /* World4 (WO4 SKU) */
288 WOR5_ETSIC = 0x65, /* World5 (WO5 SKU) */
290 WOR01_WORLD = 0x66, /* World0-1 (WW0-1 SKU) */
291 WOR02_WORLD = 0x67, /* World0-2 (WW0-2 SKU) */
292 EU1_WORLD = 0x68, /* Same as World0-2 (WW0-2 SKU), except active scan ch1-13. No ch14 */
294 WOR9_WORLD = 0x69, /* World9 (WO9 SKU) */
295 WORA_WORLD = 0x6A, /* WorldA (WOA SKU) */
297 MKK3_MKKB = 0x80, /* Japan UNI-1 even + MKKB */
298 MKK3_MKKA2 = 0x81, /* Japan UNI-1 even + MKKA2 */
299 MKK3_MKKC = 0x82, /* Japan UNI-1 even + MKKC */
301 MKK4_MKKB = 0x83, /* Japan UNI-1 even + UNI-2 + MKKB */
302 MKK4_MKKA2 = 0x84, /* Japan UNI-1 even + UNI-2 + MKKA2 */
303 MKK4_MKKC = 0x85, /* Japan UNI-1 even + UNI-2 + MKKC */
305 MKK5_MKKB = 0x86, /* Japan UNI-1 even + UNI-2 + mid-band + MKKB */
306 MKK5_MKKA2 = 0x87, /* Japan UNI-1 even + UNI-2 + mid-band + MKKA2 */
307 MKK5_MKKC = 0x88, /* Japan UNI-1 even + UNI-2 + mid-band + MKKC */
309 MKK6_MKKB = 0x89, /* Japan UNI-1 even + UNI-1 odd MKKB */
310 MKK6_MKKA2 = 0x8A, /* Japan UNI-1 even + UNI-1 odd + MKKA2 */
311 MKK6_MKKC = 0x8B, /* Japan UNI-1 even + UNI-1 odd + MKKC */
313 MKK7_MKKB = 0x8C, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKB */
314 MKK7_MKKA2 = 0x8D, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKA2 */
315 MKK7_MKKC = 0x8E, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKC */
317 MKK8_MKKB = 0x8F, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKB */
318 MKK8_MKKA2 = 0x90, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKA2 */
319 MKK8_MKKC = 0x91, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKC */
321 /* Following definitions are used only by s/w to map old
324 MKK3_MKKA = 0xF0, /* Japan UNI-1 even + MKKA */
325 MKK3_MKKA1 = 0xF1, /* Japan UNI-1 even + MKKA1 */
326 MKK3_FCCA = 0xF2, /* Japan UNI-1 even + FCCA */
327 MKK4_MKKA = 0xF3, /* Japan UNI-1 even + UNI-2 + MKKA */
328 MKK4_MKKA1 = 0xF4, /* Japan UNI-1 even + UNI-2 + MKKA1 */
329 MKK4_FCCA = 0xF5, /* Japan UNI-1 even + UNI-2 + FCCA */
330 MKK9_MKKA = 0xF6, /* Japan UNI-1 even + 4.9GHz */
331 MKK10_MKKA = 0xF7, /* Japan UNI-1 even + UNI-2 + 4.9GHz */
334 * Regulator domains ending in a number (e.g. APL1,
335 * MK1, ETSI4, etc) apply to 5GHz channel and power
336 * information. Regulator domains ending in a letter
337 * (e.g. APLA, FCCA, etc) apply to 2.4GHz channel and
340 APL1 = 0x0150, /* LAT & Asia */
341 APL2 = 0x0250, /* LAT & Asia */
342 APL3 = 0x0350, /* Taiwan */
343 APL4 = 0x0450, /* Jordan */
344 APL5 = 0x0550, /* Chile */
345 APL6 = 0x0650, /* Singapore */
346 APL8 = 0x0850, /* Malaysia */
347 APL9 = 0x0950, /* Korea (South) ROC 3 */
349 ETSI1 = 0x0130, /* Europe & others */
350 ETSI2 = 0x0230, /* Europe & others */
351 ETSI3 = 0x0330, /* Europe & others */
352 ETSI4 = 0x0430, /* Europe & others */
353 ETSI5 = 0x0530, /* Europe & others */
354 ETSI6 = 0x0630, /* Europe & others */
355 ETSIA = 0x0A30, /* France */
356 ETSIB = 0x0B30, /* Israel */
357 ETSIC = 0x0C30, /* Latin America */
359 FCC1 = 0x0110, /* US & others */
360 FCC2 = 0x0120, /* Canada, Australia & New Zealand */
361 FCC3 = 0x0160, /* US w/new middle band & DFS */
362 FCC4 = 0x0165, /* US Public Safety */
365 APLD = 0x0D50, /* South Korea */
367 MKK1 = 0x0140, /* Japan (UNI-1 odd)*/
368 MKK2 = 0x0240, /* Japan (4.9 GHz + UNI-1 odd) */
369 MKK3 = 0x0340, /* Japan (UNI-1 even) */
370 MKK4 = 0x0440, /* Japan (UNI-1 even + UNI-2) */
371 MKK5 = 0x0540, /* Japan (UNI-1 even + UNI-2 + mid-band) */
372 MKK6 = 0x0640, /* Japan (UNI-1 odd + UNI-1 even) */
373 MKK7 = 0x0740, /* Japan (UNI-1 odd + UNI-1 even + UNI-2 */
374 MKK8 = 0x0840, /* Japan (UNI-1 odd + UNI-1 even + UNI-2 + mid-band) */
375 MKK9 = 0x0940, /* Japan (UNI-1 even + 4.9 GHZ) */
376 MKK10 = 0x0B40, /* Japan (UNI-1 even + UNI-2 + 4.9 GHZ) */
377 MKKA = 0x0A40, /* Japan */
382 DEBUG_REG_DMN = 0x01ff,
384 #define DEF_REGDMN FCC1_FCCA
390 #define D(_x) { #_x, _x }
392 D(NULL1_WORLD), /* For 11b-only countries (no 11a allowed) */
393 D(NULL1_ETSIB), /* Israel */
395 D(FCC1_FCCA), /* USA */
396 D(FCC1_WORLD), /* Hong Kong */
397 D(FCC4_FCCA), /* USA - Public Safety */
399 D(FCC2_FCCA), /* Canada */
400 D(FCC2_WORLD), /* Australia & HK */
402 D(FRANCE_RES), /* Legacy France for OEM */
407 D(ETSI3_ETSIA), /* France (optional) */
408 D(ETSI2_WORLD), /* Hungary & others */
409 D(ETSI3_WORLD), /* France & others */
413 D(ETSI6_WORLD), /* Bulgaria */
414 D(ETSI_RESERVED), /* Reserved (Do not used) */
416 D(MKK1_MKKA), /* Japan (JP1) */
417 D(MKK1_MKKB), /* Japan (JP0) */
418 D(APL4_WORLD), /* Singapore */
419 D(MKK2_MKKA), /* Japan with 4.9G channels */
420 D(APL_RESERVED), /* Reserved (Do not used) */
421 D(APL2_WORLD), /* Korea */
424 D(MKK1_FCCA), /* Japan (JP1-1) */
425 D(APL2_APLD), /* Korea with 2.3G channels */
426 D(MKK1_MKKA1), /* Japan (JE1) */
427 D(MKK1_MKKA2), /* Japan (JE2) */
431 D(APL1_WORLD), /* Latin America */
435 D(APL2_ETSIC), /* Venezuela */
436 D(APL5_WORLD), /* Chile */
437 D(APL6_WORLD), /* Singapore */
438 D(APL7_FCCA), /* Taiwan 5.47 Band */
439 D(APL8_WORLD), /* Malaysia 5GHz */
440 D(APL9_WORLD), /* Korea 5GHz */
442 D(WOR0_WORLD), /* World0 (WO0 SKU) */
443 D(WOR1_WORLD), /* World1 (WO1 SKU) */
444 D(WOR2_WORLD), /* World2 (WO2 SKU) */
445 D(WOR3_WORLD), /* World3 (WO3 SKU) */
446 D(WOR4_WORLD), /* World4 (WO4 SKU) */
447 D(WOR5_ETSIC), /* World5 (WO5 SKU) */
449 D(WOR01_WORLD), /* World0-1 (WW0-1 SKU) */
450 D(WOR02_WORLD), /* World0-2 (WW0-2 SKU) */
453 D(WOR9_WORLD), /* World9 (WO9 SKU) */
454 D(WORA_WORLD), /* WorldA (WOA SKU) */
456 D(MKK3_MKKB), /* Japan UNI-1 even + MKKB */
457 D(MKK3_MKKA2), /* Japan UNI-1 even + MKKA2 */
458 D(MKK3_MKKC), /* Japan UNI-1 even + MKKC */
460 D(MKK4_MKKB), /* Japan UNI-1 even + UNI-2 + MKKB */
461 D(MKK4_MKKA2), /* Japan UNI-1 even + UNI-2 + MKKA2 */
462 D(MKK4_MKKC), /* Japan UNI-1 even + UNI-2 + MKKC */
464 D(MKK5_MKKB), /* Japan UNI-1 even + UNI-2 + mid-band + MKKB */
465 D(MKK5_MKKA2), /* Japan UNI-1 even + UNI-2 + mid-band + MKKA2 */
466 D(MKK5_MKKC), /* Japan UNI-1 even + UNI-2 + mid-band + MKKC */
468 D(MKK6_MKKB), /* Japan UNI-1 even + UNI-1 odd MKKB */
469 D(MKK6_MKKA2), /* Japan UNI-1 even + UNI-1 odd + MKKA2 */
470 D(MKK6_MKKC), /* Japan UNI-1 even + UNI-1 odd + MKKC */
472 D(MKK7_MKKB), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKB */
473 D(MKK7_MKKA2), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKA2 */
474 D(MKK7_MKKC), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKC */
476 D(MKK8_MKKB), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKB */
477 D(MKK8_MKKA2), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKA2 */
478 D(MKK8_MKKC), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKC */
480 D(MKK3_MKKA), /* Japan UNI-1 even + MKKA */
481 D(MKK3_MKKA1), /* Japan UNI-1 even + MKKA1 */
482 D(MKK3_FCCA), /* Japan UNI-1 even + FCCA */
483 D(MKK4_MKKA), /* Japan UNI-1 even + UNI-2 + MKKA */
484 D(MKK4_MKKA1), /* Japan UNI-1 even + UNI-2 + MKKA1 */
485 D(MKK4_FCCA), /* Japan UNI-1 even + UNI-2 + FCCA */
486 D(MKK9_MKKA), /* Japan UNI-1 even + 4.9GHz */
487 D(MKK10_MKKA), /* Japan UNI-1 even + UNI-2 + 4.9GHz */
489 D(APL1), /* LAT & Asia */
490 D(APL2), /* LAT & Asia */
491 D(APL3), /* Taiwan */
492 D(APL4), /* Jordan */
494 D(APL6), /* Singapore */
495 D(APL8), /* Malaysia */
496 D(APL9), /* Korea (South) ROC 3 */
498 D(ETSI1), /* Europe & others */
499 D(ETSI2), /* Europe & others */
500 D(ETSI3), /* Europe & others */
501 D(ETSI4), /* Europe & others */
502 D(ETSI5), /* Europe & others */
503 D(ETSI6), /* Europe & others */
504 D(ETSIA), /* France */
505 D(ETSIB), /* Israel */
506 D(ETSIC), /* Latin America */
508 D(FCC1), /* US & others */
510 D(FCC3), /* US w/new middle band & DFS */
511 D(FCC4), /* US Public Safety */
514 D(APLD), /* South Korea */
516 D(MKK1), /* Japan (UNI-1 odd)*/
517 D(MKK2), /* Japan (4.9 GHz + UNI-1 odd) */
518 D(MKK3), /* Japan (UNI-1 even) */
519 D(MKK4), /* Japan (UNI-1 even + UNI-2) */
520 D(MKK5), /* Japan (UNI-1 even + UNI-2 + mid-band) */
521 D(MKK6), /* Japan (UNI-1 odd + UNI-1 even) */
522 D(MKK7), /* Japan (UNI-1 odd + UNI-1 even + UNI-2 */
523 D(MKK8), /* Japan (UNI-1 odd + UNI-1 even + UNI-2 + mid-band) */
524 D(MKK9), /* Japan (UNI-1 even + 4.9 GHZ) */
525 D(MKK10), /* Japan (UNI-1 even + UNI-2 + 4.9 GHZ) */
536 rdlookup(const char *name, HAL_REG_DOMAIN *rd)
538 #define N(a) (sizeof(a)/sizeof(a[0]))
541 for (i = 0; i < N(domains); i++)
542 if (strcasecmp(domains[i].name, name) == 0) {
551 getrdname(HAL_REG_DOMAIN rd)
553 #define N(a) (sizeof(a)/sizeof(a[0]))
556 for (i = 0; i < N(domains); i++)
557 if (domains[i].rd == rd)
558 return domains[i].name;
566 #define N(a) (sizeof(a)/sizeof(a[0]))
569 printf("\nRegulatory domains:\n\n");
570 for (i = 0; i < N(domains); i++)
571 printf("%-15s%s", domains[i].name,
572 ((i+1)%5) == 0 ? "\n" : "");
578 HAL_CTRY_CODE countryCode;
579 HAL_REG_DOMAIN regDmnEnum;
582 } COUNTRY_CODE_TO_ENUM_RD;
585 * Country Code Table to Enumerated RD
587 static COUNTRY_CODE_TO_ENUM_RD allCountries[] = {
588 {CTRY_DEBUG, NO_ENUMRD, "DB", "DEBUG" },
589 {CTRY_DEFAULT, DEF_REGDMN, "NA", "NO_COUNTRY_SET" },
590 {CTRY_ALBANIA, NULL1_WORLD, "AL", "ALBANIA" },
591 {CTRY_ALGERIA, NULL1_WORLD, "DZ", "ALGERIA" },
592 {CTRY_ARGENTINA, APL3_WORLD, "AR", "ARGENTINA" },
593 {CTRY_ARMENIA, ETSI4_WORLD, "AM", "ARMENIA" },
594 {CTRY_AUSTRALIA, FCC2_WORLD, "AU", "AUSTRALIA" },
595 {CTRY_AUSTRIA, ETSI1_WORLD, "AT", "AUSTRIA" },
596 {CTRY_AZERBAIJAN, ETSI4_WORLD, "AZ", "AZERBAIJAN" },
597 {CTRY_BAHRAIN, APL6_WORLD, "BH", "BAHRAIN" },
598 {CTRY_BELARUS, NULL1_WORLD, "BY", "BELARUS" },
599 {CTRY_BELGIUM, ETSI1_WORLD, "BE", "BELGIUM" },
600 {CTRY_BELIZE, APL1_ETSIC, "BZ", "BELIZE" },
601 {CTRY_BOLIVIA, APL1_ETSIC, "BO", "BOLVIA" },
602 {CTRY_BRAZIL, FCC3_WORLD, "BR", "BRAZIL" },
603 {CTRY_BRUNEI_DARUSSALAM,APL1_WORLD,"BN", "BRUNEI DARUSSALAM" },
604 {CTRY_BULGARIA, ETSI6_WORLD, "BG", "BULGARIA" },
605 {CTRY_CANADA, FCC2_FCCA, "CA", "CANADA" },
606 {CTRY_CHILE, APL6_WORLD, "CL", "CHILE" },
607 {CTRY_CHINA, APL1_WORLD, "CN", "CHINA" },
608 {CTRY_COLOMBIA, FCC1_FCCA, "CO", "COLOMBIA" },
609 {CTRY_COSTA_RICA, NULL1_WORLD, "CR", "COSTA RICA" },
610 {CTRY_CROATIA, ETSI3_WORLD, "HR", "CROATIA" },
611 {CTRY_CYPRUS, ETSI1_WORLD, "CY", "CYPRUS" },
612 {CTRY_CZECH, ETSI3_WORLD, "CZ", "CZECH REPUBLIC" },
613 {CTRY_DENMARK, ETSI1_WORLD, "DK", "DENMARK" },
614 {CTRY_DOMINICAN_REPUBLIC,FCC1_FCCA,"DO", "DOMINICAN REPUBLIC" },
615 {CTRY_ECUADOR, NULL1_WORLD, "EC", "ECUADOR" },
616 {CTRY_EGYPT, ETSI3_WORLD, "EG", "EGYPT" },
617 {CTRY_EL_SALVADOR, NULL1_WORLD, "SV", "EL SALVADOR" },
618 {CTRY_ESTONIA, ETSI1_WORLD, "EE", "ESTONIA" },
619 {CTRY_FINLAND, ETSI1_WORLD, "FI", "FINLAND" },
620 {CTRY_FRANCE, ETSI3_WORLD, "FR", "FRANCE" },
621 {CTRY_FRANCE2, ETSI3_WORLD, "F2", "FRANCE_RES" },
622 {CTRY_GEORGIA, ETSI4_WORLD, "GE", "GEORGIA" },
623 {CTRY_GERMANY, ETSI1_WORLD, "DE", "GERMANY" },
624 {CTRY_GREECE, ETSI1_WORLD, "GR", "GREECE" },
625 {CTRY_GUATEMALA, FCC1_FCCA, "GT", "GUATEMALA" },
626 {CTRY_HONDURAS, NULL1_WORLD, "HN", "HONDURAS" },
627 {CTRY_HONG_KONG, FCC2_WORLD, "HK", "HONG KONG" },
628 {CTRY_HUNGARY, ETSI1_WORLD, "HU", "HUNGARY" },
629 {CTRY_ICELAND, ETSI1_WORLD, "IS", "ICELAND" },
630 {CTRY_INDIA, APL6_WORLD, "IN", "INDIA" },
631 {CTRY_INDONESIA, APL1_WORLD, "ID", "INDONESIA" },
632 {CTRY_IRAN, APL1_WORLD, "IR", "IRAN" },
633 {CTRY_IRELAND, ETSI1_WORLD, "IE", "IRELAND" },
634 {CTRY_ISRAEL, NULL1_WORLD, "IL", "ISRAEL" },
635 {CTRY_ITALY, ETSI1_WORLD, "IT", "ITALY" },
636 {CTRY_JAPAN, MKK1_MKKA, "JP", "JAPAN" },
637 {CTRY_JAPAN1, MKK1_MKKB, "JP", "JAPAN1" },
638 {CTRY_JAPAN2, MKK1_FCCA, "JP", "JAPAN2" },
639 {CTRY_JAPAN3, MKK2_MKKA, "JP", "JAPAN3" },
640 {CTRY_JAPAN4, MKK1_MKKA1, "JP", "JAPAN4" },
641 {CTRY_JAPAN5, MKK1_MKKA2, "JP", "JAPAN5" },
642 {CTRY_JAPAN6, MKK1_MKKC, "JP", "JAPAN6" },
644 {CTRY_JAPAN7, MKK3_MKKB, "JP", "JAPAN7" },
645 {CTRY_JAPAN8, MKK3_MKKA2, "JP", "JAPAN8" },
646 {CTRY_JAPAN9, MKK3_MKKC, "JP", "JAPAN9" },
648 {CTRY_JAPAN10, MKK4_MKKB, "JP", "JAPAN10" },
649 {CTRY_JAPAN11, MKK4_MKKA2, "JP", "JAPAN11" },
650 {CTRY_JAPAN12, MKK4_MKKC, "JP", "JAPAN12" },
652 {CTRY_JAPAN13, MKK5_MKKB, "JP", "JAPAN13" },
653 {CTRY_JAPAN14, MKK5_MKKA2, "JP", "JAPAN14" },
654 {CTRY_JAPAN15, MKK5_MKKC, "JP", "JAPAN15" },
656 {CTRY_JAPAN16, MKK6_MKKB, "JP", "JAPAN16" },
657 {CTRY_JAPAN17, MKK6_MKKA2, "JP", "JAPAN17" },
658 {CTRY_JAPAN18, MKK6_MKKC, "JP", "JAPAN18" },
660 {CTRY_JAPAN19, MKK7_MKKB, "JP", "JAPAN19" },
661 {CTRY_JAPAN20, MKK7_MKKA2, "JP", "JAPAN20" },
662 {CTRY_JAPAN21, MKK7_MKKC, "JP", "JAPAN21" },
664 {CTRY_JAPAN22, MKK8_MKKB, "JP", "JAPAN22" },
665 {CTRY_JAPAN23, MKK8_MKKA2, "JP", "JAPAN23" },
666 {CTRY_JAPAN24, MKK8_MKKC, "JP", "JAPAN24" },
668 {CTRY_JORDAN, APL4_WORLD, "JO", "JORDAN" },
669 {CTRY_KAZAKHSTAN, NULL1_WORLD, "KZ", "KAZAKHSTAN" },
670 {CTRY_KOREA_NORTH, APL2_WORLD, "KP", "NORTH KOREA" },
671 {CTRY_KOREA_ROC, APL2_WORLD, "KR", "KOREA REPUBLIC" },
672 {CTRY_KOREA_ROC2, APL2_WORLD, "K2", "KOREA REPUBLIC2" },
673 {CTRY_KOREA_ROC3, APL9_WORLD, "K3", "KOREA REPUBLIC3" },
674 {CTRY_KUWAIT, NULL1_WORLD, "KW", "KUWAIT" },
675 {CTRY_LATVIA, ETSI1_WORLD, "LV", "LATVIA" },
676 {CTRY_LEBANON, NULL1_WORLD, "LB", "LEBANON" },
677 {CTRY_LIECHTENSTEIN,ETSI1_WORLD, "LI", "LIECHTENSTEIN" },
678 {CTRY_LITHUANIA, ETSI1_WORLD, "LT", "LITHUANIA" },
679 {CTRY_LUXEMBOURG, ETSI1_WORLD, "LU", "LUXEMBOURG" },
680 {CTRY_MACAU, FCC2_WORLD, "MO", "MACAU" },
681 {CTRY_MACEDONIA, NULL1_WORLD, "MK", "MACEDONIA" },
682 {CTRY_MALAYSIA, APL8_WORLD, "MY", "MALAYSIA" },
683 {CTRY_MALTA, ETSI1_WORLD, "MT", "MALTA" },
684 {CTRY_MEXICO, FCC1_FCCA, "MX", "MEXICO" },
685 {CTRY_MONACO, ETSI4_WORLD, "MC", "MONACO" },
686 {CTRY_MOROCCO, NULL1_WORLD, "MA", "MOROCCO" },
687 {CTRY_NETHERLANDS, ETSI1_WORLD, "NL", "NETHERLANDS" },
688 {CTRY_NEW_ZEALAND, FCC2_ETSIC, "NZ", "NEW ZEALAND" },
689 {CTRY_NORWAY, ETSI1_WORLD, "NO", "NORWAY" },
690 {CTRY_OMAN, APL6_WORLD, "OM", "OMAN" },
691 {CTRY_PAKISTAN, NULL1_WORLD, "PK", "PAKISTAN" },
692 {CTRY_PANAMA, FCC1_FCCA, "PA", "PANAMA" },
693 {CTRY_PERU, APL1_WORLD, "PE", "PERU" },
694 {CTRY_PHILIPPINES, APL1_WORLD, "PH", "PHILIPPINES" },
695 {CTRY_POLAND, ETSI1_WORLD, "PL", "POLAND" },
696 {CTRY_PORTUGAL, ETSI1_WORLD, "PT", "PORTUGAL" },
697 {CTRY_PUERTO_RICO, FCC1_FCCA, "PR", "PUERTO RICO" },
698 {CTRY_QATAR, NULL1_WORLD, "QA", "QATAR" },
699 {CTRY_ROMANIA, NULL1_WORLD, "RO", "ROMANIA" },
700 {CTRY_RUSSIA, NULL1_WORLD, "RU", "RUSSIA" },
701 {CTRY_SAUDI_ARABIA,NULL1_WORLD, "SA", "SAUDI ARABIA" },
702 {CTRY_SINGAPORE, APL6_WORLD, "SG", "SINGAPORE" },
703 {CTRY_SLOVAKIA, ETSI1_WORLD, "SK", "SLOVAK REPUBLIC" },
704 {CTRY_SLOVENIA, ETSI1_WORLD, "SI", "SLOVENIA" },
705 {CTRY_SOUTH_AFRICA,FCC3_WORLD, "ZA", "SOUTH AFRICA" },
706 {CTRY_SPAIN, ETSI1_WORLD, "ES", "SPAIN" },
707 {CTRY_SWEDEN, ETSI1_WORLD, "SE", "SWEDEN" },
708 {CTRY_SWITZERLAND, ETSI1_WORLD, "CH", "SWITZERLAND" },
709 {CTRY_SYRIA, NULL1_WORLD, "SY", "SYRIA" },
710 {CTRY_TAIWAN, APL3_FCCA, "TW", "TAIWAN" },
711 {CTRY_THAILAND, NULL1_WORLD, "TH", "THAILAND" },
712 {CTRY_TRINIDAD_Y_TOBAGO,ETSI4_WORLD,"TT", "TRINIDAD & TOBAGO" },
713 {CTRY_TUNISIA, ETSI3_WORLD, "TN", "TUNISIA" },
714 {CTRY_TURKEY, ETSI3_WORLD, "TR", "TURKEY" },
715 {CTRY_UKRAINE, NULL1_WORLD, "UA", "UKRAINE" },
716 {CTRY_UAE, NULL1_WORLD, "AE", "UNITED ARAB EMIRATES" },
717 {CTRY_UNITED_KINGDOM, ETSI1_WORLD,"GB", "UNITED KINGDOM" },
718 {CTRY_UNITED_STATES, FCC1_FCCA, "US", "UNITED STATES" },
719 {CTRY_UNITED_STATES_FCC49, FCC4_FCCA, "PS", "UNITED STATES (PUBLIC SAFETY)" },
720 {CTRY_URUGUAY, APL2_WORLD, "UY", "URUGUAY" },
721 {CTRY_UZBEKISTAN, FCC3_FCCA, "UZ", "UZBEKISTAN" },
722 {CTRY_VENEZUELA, APL2_ETSIC, "VE", "VENEZUELA" },
723 {CTRY_VIET_NAM, NULL1_WORLD, "VN", "VIET NAM" },
724 {CTRY_YEMEN, NULL1_WORLD, "YE", "YEMEN" },
725 {CTRY_ZIMBABWE, NULL1_WORLD, "ZW", "ZIMBABWE" }
729 cclookup(const char *name, HAL_REG_DOMAIN *rd, HAL_CTRY_CODE *cc)
731 #define N(a) (sizeof(a)/sizeof(a[0]))
734 for (i = 0; i < N(allCountries); i++)
735 if (strcasecmp(allCountries[i].isoName, name) == 0 ||
736 strcasecmp(allCountries[i].name, name) == 0) {
737 *rd = allCountries[i].regDmnEnum;
738 *cc = allCountries[i].countryCode;
746 getccname(HAL_CTRY_CODE cc)
748 #define N(a) (sizeof(a)/sizeof(a[0]))
751 for (i = 0; i < N(allCountries); i++)
752 if (allCountries[i].countryCode == cc)
753 return allCountries[i].name;
759 getccisoname(HAL_CTRY_CODE cc)
761 #define N(a) (sizeof(a)/sizeof(a[0]))
764 for (i = 0; i < N(allCountries); i++)
765 if (allCountries[i].countryCode == cc)
766 return allCountries[i].isoName;
774 #define N(a) (sizeof(a)/sizeof(a[0]))
777 printf("\nCountry codes:\n");
778 for (i = 0; i < N(allCountries); i++)
779 printf("%2s %-15.15s%s",
780 allCountries[i].isoName,
781 allCountries[i].name,
782 ((i+1)%4) == 0 ? "\n" : " ");
788 setRateTable(struct ath_hal *ah, const struct ieee80211_channel *chan,
789 int16_t tpcScaleReduction, int16_t powerLimit,
790 int16_t *pMinPower, int16_t *pMaxPower);
793 calctxpower(struct ath_hal *ah,
794 int nchan, const struct ieee80211_channel *chans,
795 int16_t tpcScaleReduction, int16_t powerLimit, int16_t *txpow)
800 for (i = 0; i < nchan; i++)
801 if (!setRateTable(ah, &chans[i],
802 tpcScaleReduction, powerLimit, &minpow, &txpow[i])) {
803 printf("unable to set rate table\n");
809 const char *sep = "";
811 int showchannels = 0;
816 anychan(const struct ieee80211_channel *chans, int nc, int flag)
820 for (i = 0; i < nc; i++)
821 if ((chans[i].ic_flags & flag) != 0)
827 mapgsm(u_int freq, u_int flags)
830 if (flags & IEEE80211_CHAN_QUARTER)
832 else if (flags & IEEE80211_CHAN_HALF)
836 return (freq - 24220) / 5;
840 mappsb(u_int freq, u_int flags)
842 return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
846 * Convert GHz frequency to IEEE channel number.
849 ath_hal_mhz2ieee(struct ath_hal *ah, u_int freq, u_int flags)
851 if (flags & IEEE80211_CHAN_2GHZ) { /* 2GHz band */
855 return ((int)freq - 2407) / 5;
857 return 15 + ((freq - 2512) / 20);
858 } else if (flags & IEEE80211_CHAN_5GHZ) {/* 5Ghz band */
859 if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq))
860 return mappsb(freq, flags);
861 else if ((flags & IEEE80211_CHAN_A) && (freq <= 5000))
862 return (freq - 4000) / 5;
864 return (freq - 5000) / 5;
865 } else { /* either, guess */
869 return ((int)freq - 2407) / 5;
871 if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq))
872 return mappsb(freq, flags);
873 else if (freq > 4900)
874 return (freq - 4000) / 5;
876 return 15 + ((freq - 2512) / 20);
878 return (freq - 5000) / 5;
882 #define IEEE80211_IS_CHAN_4MS(_c) \
883 (((_c)->ic_flags & IEEE80211_CHAN_4MSXMIT) != 0)
886 dumpchannels(struct ath_hal *ah, int nc,
887 const struct ieee80211_channel *chans, int16_t *txpow)
891 for (i = 0; i < nc; i++) {
892 const struct ieee80211_channel *c = &chans[i];
897 ath_hal_mhz2ieee(ah, c->ic_freq, c->ic_flags));
899 printf("%s%u", sep, c->ic_freq);
900 if (IEEE80211_IS_CHAN_HALF(c))
902 else if (IEEE80211_IS_CHAN_QUARTER(c))
904 else if (IEEE80211_IS_CHAN_TURBO(c))
906 else if (IEEE80211_IS_CHAN_HT(c))
908 else if (IEEE80211_IS_CHAN_A(c))
910 else if (IEEE80211_IS_CHAN_108G(c))
912 else if (IEEE80211_IS_CHAN_G(c))
916 if (dopassive && IEEE80211_IS_CHAN_PASSIVE(c))
917 type = tolower(type);
919 printf("%c%c%c %d.%d", type,
920 IEEE80211_IS_CHAN_DFS(c) ? '*' : ' ',
921 IEEE80211_IS_CHAN_4MS(c) ? '4' : ' ',
922 txpow[i]/2, (txpow[i]%2)*5);
924 printf("%c%c %d.%d", type,
925 IEEE80211_IS_CHAN_DFS(c) ? '*' : ' ',
926 txpow[i]/2, (txpow[i]%2)*5);
928 printf("%c%c %d.%d", type,
929 IEEE80211_IS_CHAN_4MS(c) ? '4' : ' ',
930 txpow[i]/2, (txpow[i]%2)*5);
932 printf("%c %d.%d", type, txpow[i]/2, (txpow[i]%2)*5);
933 if ((n++ % (showchannels ? 7 : 6)) == 0)
941 intersect(struct ieee80211_channel *dst, int16_t *dtxpow, int *nd,
942 const struct ieee80211_channel *src, int16_t *stxpow, int ns)
946 for (j = 0; j < ns && dst[i].ic_freq != src[j].ic_freq; j++)
948 if (j < ns && dtxpow[i] == stxpow[j]) {
949 for (k = i+1, l = i; k < *nd; k++, l++)
958 usage(const char *progname)
960 printf("usage: %s [-acdefoilpr4ABGT] [-m opmode] [cc | rd]\n", progname);
965 getChipPowerLimits(struct ath_hal *ah, struct ieee80211_channel *chan)
970 eepromRead(struct ath_hal *ah, u_int off, u_int16_t *data)
972 /* emulate enough stuff to handle japan channel shift */
974 case AR_EEPROM_VERSION:
977 case AR_EEPROM_REG_CAPABILITIES_OFFSET:
978 *data = AR_EEPROM_EEREGCAP_EN_KK_NEW_11A;
980 case AR_EEPROM_REG_CAPABILITIES_OFFSET_PRE4_0:
981 *data = AR_EEPROM_EEREGCAP_EN_KK_NEW_11A_PRE4_0;
988 getCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
989 uint32_t capability, uint32_t *result)
991 const HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
994 case HAL_CAP_REG_DMN: /* regulatory domain */
995 *result = AH_PRIVATE(ah)->ah_currentRD;
1002 #define HAL_MODE_HT20 \
1003 (HAL_MODE_11NG_HT20 | HAL_MODE_11NA_HT20)
1004 #define HAL_MODE_HT40 \
1005 (HAL_MODE_11NG_HT40PLUS | HAL_MODE_11NG_HT40MINUS | \
1006 HAL_MODE_11NA_HT40PLUS | HAL_MODE_11NA_HT40MINUS)
1007 #define HAL_MODE_HT (HAL_MODE_HT20 | HAL_MODE_HT40)
1010 main(int argc, char *argv[])
1012 static const u_int16_t tpcScaleReductionTable[5] =
1013 { 0, 3, 6, 9, MAX_RATE_POWER };
1014 struct ath_hal_private ahp;
1015 struct ieee80211_channel achans[IEEE80211_CHAN_MAX];
1016 int16_t atxpow[IEEE80211_CHAN_MAX];
1017 struct ieee80211_channel bchans[IEEE80211_CHAN_MAX];
1018 int16_t btxpow[IEEE80211_CHAN_MAX];
1019 struct ieee80211_channel gchans[IEEE80211_CHAN_MAX];
1020 int16_t gtxpow[IEEE80211_CHAN_MAX];
1021 struct ieee80211_channel tchans[IEEE80211_CHAN_MAX];
1022 int16_t ttxpow[IEEE80211_CHAN_MAX];
1023 struct ieee80211_channel tgchans[IEEE80211_CHAN_MAX];
1024 int16_t tgtxpow[IEEE80211_CHAN_MAX];
1025 struct ieee80211_channel nchans[IEEE80211_CHAN_MAX];
1026 int16_t ntxpow[IEEE80211_CHAN_MAX];
1027 int i, na, nb, ng, nt, ntg, nn;
1028 HAL_BOOL showall = AH_FALSE;
1029 HAL_BOOL extendedChanMode = AH_TRUE;
1031 int16_t tpcReduction, powerLimit;
1035 memset(&ahp, 0, sizeof(ahp));
1036 ahp.ah_getChannelEdges = getChannelEdges;
1037 ahp.ah_getWirelessModes = getWirelessModes;
1038 ahp.ah_eepromRead = eepromRead;
1039 ahp.ah_getChipPowerLimits = getChipPowerLimits;
1040 ahp.ah_caps.halWirelessModes = HAL_MODE_ALL;
1041 ahp.ah_caps.halLow5GhzChan = 4920;
1042 ahp.ah_caps.halHigh5GhzChan = 6100;
1043 ahp.ah_caps.halLow2GhzChan = 2312;
1044 ahp.ah_caps.halHigh2GhzChan = 2732;
1045 ahp.ah_caps.halChanHalfRate = AH_TRUE;
1046 ahp.ah_caps.halChanQuarterRate = AH_TRUE;
1047 ahp.h.ah_getCapability = getCapability;
1048 ahp.ah_opmode = HAL_M_STA;
1050 tpcReduction = tpcScaleReductionTable[0];
1051 powerLimit = MAX_RATE_POWER;
1053 while ((i = getopt(argc, argv, "acdeflm:pr4ABGhHNT")) != -1)
1059 showchannels = AH_TRUE;
1062 ath_hal_debug = HAL_DEBUG_ANY;
1065 extendedChanMode = AH_FALSE;
1068 showchannels = AH_FALSE;
1075 if (strncasecmp(optarg, "sta", 2) == 0)
1076 ahp.ah_opmode = HAL_M_STA;
1077 else if (strncasecmp(optarg, "ibss", 2) == 0)
1078 ahp.ah_opmode = HAL_M_IBSS;
1079 else if (strncasecmp(optarg, "adhoc", 2) == 0)
1080 ahp.ah_opmode = HAL_M_IBSS;
1081 else if (strncasecmp(optarg, "ap", 2) == 0)
1082 ahp.ah_opmode = HAL_M_HOSTAP;
1083 else if (strncasecmp(optarg, "hostap", 2) == 0)
1084 ahp.ah_opmode = HAL_M_HOSTAP;
1085 else if (strncasecmp(optarg, "monitor", 2) == 0)
1086 ahp.ah_opmode = HAL_M_MONITOR;
1094 modes |= HAL_MODE_11A;
1097 modes |= HAL_MODE_11B;
1100 modes |= HAL_MODE_11G;
1103 modes |= HAL_MODE_HT20;
1106 modes |= HAL_MODE_HT40;
1109 modes |= HAL_MODE_HT;
1112 modes |= HAL_MODE_TURBO | HAL_MODE_108G;
1123 switch (argc - optind) {
1125 if (!cclookup("US", &rd, &cc)) {
1126 printf("%s: unknown country code\n", "US");
1130 case 1: /* cc/regdomain */
1131 if (!cclookup(argv[optind], &rd, &cc)) {
1132 if (!rdlookup(argv[optind], &rd)) {
1135 rd = strtoul(argv[optind], NULL, 0);
1136 rdname = getrdname(rd);
1137 if (rdname == NULL) {
1138 printf("%s: unknown country/regulatory "
1139 "domain code\n", argv[optind]);
1146 default: /* regdomain cc */
1147 if (!rdlookup(argv[optind], &rd)) {
1150 rd = strtoul(argv[optind], NULL, 0);
1151 rdname = getrdname(rd);
1152 if (rdname == NULL) {
1153 printf("%s: unknown country/regulatory "
1154 "domain code\n", argv[optind]);
1158 if (!cclookup(argv[optind+1], &rd, &cc))
1159 cc = strtoul(argv[optind+1], NULL, 0);
1162 if (cc != CTRY_DEFAULT)
1163 printf("\n%s (%s, 0x%x, %u) %s (0x%x, %u)\n",
1164 getccname(cc), getccisoname(cc), cc, cc,
1165 getrdname(rd), rd, rd);
1167 printf("\n%s (0x%x, %u)\n",
1168 getrdname(rd), rd, rd);
1171 /* NB: no HAL_MODE_HT */
1172 modes = HAL_MODE_11A | HAL_MODE_11B |
1173 HAL_MODE_11G | HAL_MODE_TURBO | HAL_MODE_108G;
1175 na = nb = ng = nt = ntg = nn = 0;
1176 if (modes & HAL_MODE_11G) {
1177 ahp.ah_currentRD = rd;
1178 if (ath_hal_getchannels(&ahp.h, gchans, IEEE80211_CHAN_MAX, &ng,
1179 HAL_MODE_11G, cc, rd, extendedChanMode) == HAL_OK) {
1180 calctxpower(&ahp.h, ng, gchans, tpcReduction, powerLimit, gtxpow);
1182 isdfs |= anychan(gchans, ng, IEEE80211_CHAN_DFS);
1184 is4ms |= anychan(gchans, ng, IEEE80211_CHAN_4MSXMIT);
1187 if (modes & HAL_MODE_11B) {
1188 ahp.ah_currentRD = rd;
1189 if (ath_hal_getchannels(&ahp.h, bchans, IEEE80211_CHAN_MAX, &nb,
1190 HAL_MODE_11B, cc, rd, extendedChanMode) == HAL_OK) {
1191 calctxpower(&ahp.h, nb, bchans, tpcReduction, powerLimit, btxpow);
1193 isdfs |= anychan(bchans, nb, IEEE80211_CHAN_DFS);
1195 is4ms |= anychan(bchans, nb, IEEE80211_CHAN_4MSXMIT);
1198 if (modes & HAL_MODE_11A) {
1199 ahp.ah_currentRD = rd;
1200 if (ath_hal_getchannels(&ahp.h, achans, IEEE80211_CHAN_MAX, &na,
1201 HAL_MODE_11A, cc, rd, extendedChanMode) == HAL_OK) {
1202 calctxpower(&ahp.h, na, achans, tpcReduction, powerLimit, atxpow);
1204 isdfs |= anychan(achans, na, IEEE80211_CHAN_DFS);
1206 is4ms |= anychan(achans, na, IEEE80211_CHAN_4MSXMIT);
1209 if (modes & HAL_MODE_TURBO) {
1210 ahp.ah_currentRD = rd;
1211 if (ath_hal_getchannels(&ahp.h, tchans, IEEE80211_CHAN_MAX, &nt,
1212 HAL_MODE_TURBO, cc, rd, extendedChanMode) == HAL_OK) {
1213 calctxpower(&ahp.h, nt, tchans, tpcReduction, powerLimit, ttxpow);
1215 isdfs |= anychan(tchans, nt, IEEE80211_CHAN_DFS);
1217 is4ms |= anychan(tchans, nt, IEEE80211_CHAN_4MSXMIT);
1220 if (modes & HAL_MODE_108G) {
1221 ahp.ah_currentRD = rd;
1222 if (ath_hal_getchannels(&ahp.h, tgchans, IEEE80211_CHAN_MAX, &ntg,
1223 HAL_MODE_108G, cc, rd, extendedChanMode) == HAL_OK) {
1224 calctxpower(&ahp.h, ntg, tgchans, tpcReduction, powerLimit, tgtxpow);
1226 isdfs |= anychan(tgchans, ntg, IEEE80211_CHAN_DFS);
1228 is4ms |= anychan(tgchans, ntg, IEEE80211_CHAN_4MSXMIT);
1231 if (modes & HAL_MODE_HT) {
1232 ahp.ah_currentRD = rd;
1233 if (ath_hal_getchannels(&ahp.h, nchans, IEEE80211_CHAN_MAX, &nn,
1234 modes & HAL_MODE_HT, cc, rd, extendedChanMode) == HAL_OK) {
1235 calctxpower(&ahp.h, nn, nchans, tpcReduction, powerLimit, ntxpow);
1237 isdfs |= anychan(nchans, nn, IEEE80211_CHAN_DFS);
1239 is4ms |= anychan(nchans, nn, IEEE80211_CHAN_4MSXMIT);
1244 #define CHECKMODES(_modes, _m) ((_modes & (_m)) == (_m))
1245 if (CHECKMODES(modes, HAL_MODE_11B|HAL_MODE_11G)) {
1247 intersect(bchans, btxpow, &nb, gchans, gtxpow, ng);
1249 if (CHECKMODES(modes, HAL_MODE_11A|HAL_MODE_TURBO)) {
1251 intersect(tchans, ttxpow, &nt, achans, atxpow, na);
1253 if (CHECKMODES(modes, HAL_MODE_11G|HAL_MODE_108G)) {
1255 intersect(tgchans, tgtxpow, &ntg, gchans, gtxpow, ng);
1257 if (CHECKMODES(modes, HAL_MODE_11G|HAL_MODE_HT)) {
1259 intersect(gchans, gtxpow, &ng, nchans, ntxpow, nn);
1261 if (CHECKMODES(modes, HAL_MODE_11A|HAL_MODE_HT)) {
1263 intersect(achans, atxpow, &na, nchans, ntxpow, nn);
1268 if (modes & HAL_MODE_11G)
1269 dumpchannels(&ahp.h, ng, gchans, gtxpow);
1270 if (modes & HAL_MODE_11B)
1271 dumpchannels(&ahp.h, nb, bchans, btxpow);
1272 if (modes & HAL_MODE_11A)
1273 dumpchannels(&ahp.h, na, achans, atxpow);
1274 if (modes & HAL_MODE_108G)
1275 dumpchannels(&ahp.h, ntg, tgchans, tgtxpow);
1276 if (modes & HAL_MODE_TURBO)
1277 dumpchannels(&ahp.h, nt, tchans, ttxpow);
1278 if (modes & HAL_MODE_HT)
1279 dumpchannels(&ahp.h, nn, nchans, ntxpow);
1285 * Search a list for a specified value v that is within
1286 * EEP_DELTA of the search values. Return the closest
1287 * values in the list above and below the desired value.
1288 * EEP_DELTA is a factional value; everything is scaled
1289 * so only integer arithmetic is used.
1291 * NB: the input list is assumed to be sorted in ascending order
1294 ar5212GetLowerUpperValues(u_int16_t v, u_int16_t *lp, u_int16_t listSize,
1295 u_int16_t *vlo, u_int16_t *vhi)
1297 u_int32_t target = v * EEP_SCALE;
1298 u_int16_t *ep = lp+listSize;
1301 * Check first and last elements for out-of-bounds conditions.
1303 if (target < (u_int32_t)(lp[0] * EEP_SCALE - EEP_DELTA)) {
1304 *vlo = *vhi = lp[0];
1307 if (target > (u_int32_t)(ep[-1] * EEP_SCALE + EEP_DELTA)) {
1308 *vlo = *vhi = ep[-1];
1312 /* look for value being near or between 2 values in list */
1313 for (; lp < ep; lp++) {
1315 * If value is close to the current value of the list
1316 * then target is not between values, it is one of the values
1318 if (abs(lp[0] * EEP_SCALE - target) < EEP_DELTA) {
1319 *vlo = *vhi = lp[0];
1323 * Look for value being between current value and next value
1324 * if so return these 2 values
1326 if (target < (u_int32_t)(lp[1] * EEP_SCALE - EEP_DELTA)) {
1335 * Find the maximum conformance test limit for the given channel and CTL info
1338 ar5212GetMaxEdgePower(u_int16_t channel, RD_EDGES_POWER *pRdEdgesPower)
1340 /* temp array for holding edge channels */
1341 u_int16_t tempChannelList[NUM_EDGES];
1342 u_int16_t clo, chi, twiceMaxEdgePower;
1345 /* Get the edge power */
1346 for (i = 0; i < NUM_EDGES; i++) {
1347 if (pRdEdgesPower[i].rdEdge == 0)
1349 tempChannelList[i] = pRdEdgesPower[i].rdEdge;
1353 ar5212GetLowerUpperValues(channel, tempChannelList,
1354 numEdges, &clo, &chi);
1355 /* Get the index for the lower channel */
1356 for (i = 0; i < numEdges && clo != tempChannelList[i]; i++)
1358 /* Is lower channel ever outside the rdEdge? */
1359 HALASSERT(i != numEdges);
1361 if ((clo == chi && clo == channel) || (pRdEdgesPower[i].flag)) {
1363 * If there's an exact channel match or an inband flag set
1364 * on the lower channel use the given rdEdgePower
1366 twiceMaxEdgePower = pRdEdgesPower[i].twice_rdEdgePower;
1367 HALASSERT(twiceMaxEdgePower > 0);
1369 twiceMaxEdgePower = MAX_RATE_POWER;
1370 return twiceMaxEdgePower;
1374 * Returns interpolated or the scaled up interpolated value
1377 interpolate(u_int16_t target, u_int16_t srcLeft, u_int16_t srcRight,
1378 u_int16_t targetLeft, u_int16_t targetRight)
1383 /* to get an accurate ratio, always scale, if want to scale, then don't scale back down */
1384 if ((targetLeft * targetRight) == 0)
1387 if (srcRight != srcLeft) {
1389 * Note the ratio always need to be scaled,
1390 * since it will be a fraction.
1392 lRatio = (target - srcLeft) * EEP_SCALE / (srcRight - srcLeft);
1394 /* Return as Left target if value would be negative */
1396 } else if (lRatio > EEP_SCALE) {
1397 /* Return as Right target if Ratio is greater than 100% (SCALE) */
1400 rv = (lRatio * targetRight + (EEP_SCALE - lRatio) *
1401 targetLeft) / EEP_SCALE;
1410 * Return the four rates of target power for the given target power table
1411 * channel, and number of channels
1414 ar5212GetTargetPowers(struct ath_hal *ah, const struct ieee80211_channel *chan,
1415 TRGT_POWER_INFO *powInfo,
1416 u_int16_t numChannels, TRGT_POWER_INFO *pNewPower)
1418 /* temp array for holding target power channels */
1419 u_int16_t tempChannelList[NUM_TEST_FREQUENCIES];
1420 u_int16_t clo, chi, ixlo, ixhi;
1423 /* Copy the target powers into the temp channel list */
1424 for (i = 0; i < numChannels; i++)
1425 tempChannelList[i] = powInfo[i].testChannel;
1427 ar5212GetLowerUpperValues(chan->ic_freq, tempChannelList,
1428 numChannels, &clo, &chi);
1430 /* Get the indices for the channel */
1432 for (i = 0; i < numChannels; i++) {
1433 if (clo == tempChannelList[i]) {
1436 if (chi == tempChannelList[i]) {
1443 * Get the lower and upper channels, target powers,
1444 * and interpolate between them.
1446 pNewPower->twicePwr6_24 = interpolate(chan->ic_freq, clo, chi,
1447 powInfo[ixlo].twicePwr6_24, powInfo[ixhi].twicePwr6_24);
1448 pNewPower->twicePwr36 = interpolate(chan->ic_freq, clo, chi,
1449 powInfo[ixlo].twicePwr36, powInfo[ixhi].twicePwr36);
1450 pNewPower->twicePwr48 = interpolate(chan->ic_freq, clo, chi,
1451 powInfo[ixlo].twicePwr48, powInfo[ixhi].twicePwr48);
1452 pNewPower->twicePwr54 = interpolate(chan->ic_freq, clo, chi,
1453 powInfo[ixlo].twicePwr54, powInfo[ixhi].twicePwr54);
1456 static RD_EDGES_POWER*
1457 findEdgePower(struct ath_hal *ah, u_int ctl)
1461 for (i = 0; i < _numCtls; i++)
1463 return &_rdEdgesPower[i * NUM_EDGES];
1468 * Sets the transmit power in the baseband for the given
1469 * operating channel and mode.
1472 setRateTable(struct ath_hal *ah, const struct ieee80211_channel *chan,
1473 int16_t tpcScaleReduction, int16_t powerLimit,
1474 int16_t *pMinPower, int16_t *pMaxPower)
1476 u_int16_t ratesArray[16];
1477 u_int16_t *rpow = ratesArray;
1478 u_int16_t twiceMaxRDPower, twiceMaxEdgePower, twiceMaxEdgePowerCck;
1479 int8_t twiceAntennaGain, twiceAntennaReduction;
1480 TRGT_POWER_INFO targetPowerOfdm, targetPowerCck;
1481 RD_EDGES_POWER *rep;
1482 int16_t scaledPower;
1485 twiceMaxRDPower = chan->ic_maxregpower * 2;
1486 *pMaxPower = -MAX_RATE_POWER;
1487 *pMinPower = MAX_RATE_POWER;
1489 /* Get conformance test limit maximum for this channel */
1490 cfgCtl = ath_hal_getctl(ah, chan);
1491 rep = findEdgePower(ah, cfgCtl);
1493 twiceMaxEdgePower = ar5212GetMaxEdgePower(chan->ic_freq, rep);
1495 twiceMaxEdgePower = MAX_RATE_POWER;
1497 if (IEEE80211_IS_CHAN_G(chan)) {
1498 /* Check for a CCK CTL for 11G CCK powers */
1499 cfgCtl = (cfgCtl & 0xFC) | 0x01;
1500 rep = findEdgePower(ah, cfgCtl);
1502 twiceMaxEdgePowerCck = ar5212GetMaxEdgePower(chan->ic_freq, rep);
1504 twiceMaxEdgePowerCck = MAX_RATE_POWER;
1506 /* Set the 11B cck edge power to the one found before */
1507 twiceMaxEdgePowerCck = twiceMaxEdgePower;
1510 /* Get Antenna Gain reduction */
1511 if (IEEE80211_IS_CHAN_5GHZ(chan)) {
1512 twiceAntennaGain = antennaGainMax[0];
1514 twiceAntennaGain = antennaGainMax[1];
1516 twiceAntennaReduction =
1517 ath_hal_getantennareduction(ah, chan, twiceAntennaGain);
1519 if (IEEE80211_IS_CHAN_OFDM(chan)) {
1520 /* Get final OFDM target powers */
1521 if (IEEE80211_IS_CHAN_G(chan)) {
1522 /* TODO - add Turbo 2.4 to this mode check */
1523 ar5212GetTargetPowers(ah, chan, trgtPwr_11g,
1524 numTargetPwr_11g, &targetPowerOfdm);
1526 ar5212GetTargetPowers(ah, chan, trgtPwr_11a,
1527 numTargetPwr_11a, &targetPowerOfdm);
1530 /* Get Maximum OFDM power */
1531 /* Minimum of target and edge powers */
1532 scaledPower = AH_MIN(twiceMaxEdgePower,
1533 twiceMaxRDPower - twiceAntennaReduction);
1536 * If turbo is set, reduce power to keep power
1537 * consumption under 2 Watts. Note that we always do
1538 * this unless specially configured. Then we limit
1539 * power only for non-AP operation.
1541 if (IEEE80211_IS_CHAN_TURBO(chan)
1542 #ifdef AH_ENABLE_AP_SUPPORT
1543 && AH_PRIVATE(ah)->ah_opmode != HAL_M_HOSTAP
1547 * If turbo is set, reduce power to keep power
1548 * consumption under 2 Watts
1550 if (eeversion >= AR_EEPROM_VER3_1)
1551 scaledPower = AH_MIN(scaledPower,
1554 * EEPROM version 4.0 added an additional
1555 * constraint on 2.4GHz channels.
1557 if (eeversion >= AR_EEPROM_VER4_0 &&
1558 IEEE80211_IS_CHAN_2GHZ(chan))
1559 scaledPower = AH_MIN(scaledPower,
1562 /* Reduce power by max regulatory domain allowed restrictions */
1563 scaledPower -= (tpcScaleReduction * 2);
1564 scaledPower = (scaledPower < 0) ? 0 : scaledPower;
1565 scaledPower = AH_MIN(scaledPower, powerLimit);
1567 scaledPower = AH_MIN(scaledPower, targetPowerOfdm.twicePwr6_24);
1569 /* Set OFDM rates 9, 12, 18, 24, 36, 48, 54, XR */
1570 rpow[0] = rpow[1] = rpow[2] = rpow[3] = rpow[4] = scaledPower;
1571 rpow[5] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr36);
1572 rpow[6] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr48);
1573 rpow[7] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr54);
1576 if (eeversion >= AR_EEPROM_VER4_0) {
1577 /* Setup XR target power from EEPROM */
1578 rpow[15] = AH_MIN(scaledPower, IS_CHAN_2GHZ(chan) ?
1579 xrTargetPower2 : xrTargetPower5);
1581 /* XR uses 6mb power */
1588 *pMinPower = rpow[7];
1589 *pMaxPower = rpow[0];
1592 ahp->ah_ofdmTxPower = rpow[0];
1595 HALDEBUG(ah, HAL_DEBUG_ANY,
1596 "%s: MaxRD: %d TurboMax: %d MaxCTL: %d "
1597 "TPC_Reduction %d\n", __func__,
1598 twiceMaxRDPower, turbo2WMaxPower5,
1599 twiceMaxEdgePower, tpcScaleReduction * 2);
1602 if (IEEE80211_IS_CHAN_CCK(chan)) {
1603 /* Get final CCK target powers */
1604 ar5212GetTargetPowers(ah, chan, trgtPwr_11b,
1605 numTargetPwr_11b, &targetPowerCck);
1607 /* Reduce power by max regulatory domain allowed restrictions */
1608 scaledPower = AH_MIN(twiceMaxEdgePowerCck,
1609 twiceMaxRDPower - twiceAntennaReduction);
1611 scaledPower -= (tpcScaleReduction * 2);
1612 scaledPower = (scaledPower < 0) ? 0 : scaledPower;
1613 scaledPower = AH_MIN(scaledPower, powerLimit);
1615 rpow[8] = (scaledPower < 1) ? 1 : scaledPower;
1617 /* Set CCK rates 2L, 2S, 5.5L, 5.5S, 11L, 11S */
1618 rpow[8] = AH_MIN(scaledPower, targetPowerCck.twicePwr6_24);
1619 rpow[9] = AH_MIN(scaledPower, targetPowerCck.twicePwr36);
1621 rpow[11] = AH_MIN(scaledPower, targetPowerCck.twicePwr48);
1622 rpow[12] = rpow[11];
1623 rpow[13] = AH_MIN(scaledPower, targetPowerCck.twicePwr54);
1624 rpow[14] = rpow[13];
1626 /* Set min/max power based off OFDM values or initialization */
1627 if (rpow[13] < *pMinPower)
1628 *pMinPower = rpow[13];
1629 if (rpow[9] > *pMaxPower)
1630 *pMaxPower = rpow[9];
1634 ahp->ah_tx6PowerInHalfDbm = *pMaxPower;
1640 ath_hal_malloc(size_t size)
1642 return calloc(1, size);
1646 ath_hal_free(void* p)
1652 ath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap)
1658 ath_hal_printf(struct ath_hal *ah, const char* fmt, ...)
1662 ath_hal_vprintf(ah, fmt, ap);
1667 DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
1671 ath_hal_vprintf(ah, fmt, ap);