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 */
47 int ath_hal_debug = 0;
48 HAL_CTRY_CODE cc = CTRY_DEFAULT;
49 HAL_REG_DOMAIN rd = 169; /* FCC */
53 HAL_BOOL HT20mode = 1;
54 HAL_BOOL HT40mode = 1;
55 HAL_BOOL turbo5Disable = AH_FALSE;
56 HAL_BOOL turbo2Disable = AH_FALSE;
58 u_int16_t _numCtls = 8;
60 { 0x10, 0x13, 0x40, 0x30, 0x11, 0x31, 0x12, 0x32 };
61 RD_EDGES_POWER _rdEdgesPower[NUM_EDGES*NUM_CTLS] = {
62 { 5180, 28, 0 }, /* 0x10 */
71 { 5210, 28, 0 }, /* 0x13 */
80 { 5170, 60, 0 }, /* 0x40 */
89 { 5180, 33, 0 }, /* 0x30 */
98 { 2412, 36, 0 }, /* 0x11 */
107 { 2412, 36, 0 }, /* 0x31 */
116 { 2412, 36, 0 }, /* 0x12 */
125 { 2412, 28, 0 }, /* 0x32 */
135 u_int16_t turbo2WMaxPower5 = 32;
136 u_int16_t turbo2WMaxPower2;
137 int8_t antennaGainMax[2] = { 0, 0 }; /* XXX */
138 int eeversion = AR_EEPROM_VER3_1;
139 TRGT_POWER_ALL_MODES tpow = {
141 { 22, 24, 28, 32, 5180 },
142 { 22, 24, 28, 32, 5200 },
143 { 22, 24, 28, 32, 5320 },
144 { 26, 30, 34, 34, 5500 },
145 { 26, 30, 34, 34, 5700 },
146 { 20, 30, 34, 36, 5745 },
147 { 20, 30, 34, 36, 5825 },
148 { 20, 30, 34, 36, 5850 },
151 { 23, 27, 31, 34, 2412 },
152 { 23, 27, 31, 34, 2447 },
155 { 36, 36, 36, 36, 2412 },
156 { 36, 36, 36, 36, 2484 },
159 #define numTargetPwr_11a tpow.numTargetPwr_11a
160 #define trgtPwr_11a tpow.trgtPwr_11a
161 #define numTargetPwr_11g tpow.numTargetPwr_11g
162 #define trgtPwr_11g tpow.trgtPwr_11g
163 #define numTargetPwr_11b tpow.numTargetPwr_11b
164 #define trgtPwr_11b tpow.trgtPwr_11b
167 getChannelEdges(struct ath_hal *ah, u_int16_t flags, u_int16_t *low, u_int16_t *high)
169 struct ath_hal_private *ahp = AH_PRIVATE(ah);
170 HAL_CAPABILITIES *pCap = &ahp->ah_caps;
172 if (flags & IEEE80211_CHAN_5GHZ) {
173 *low = pCap->halLow5GhzChan;
174 *high = pCap->halHigh5GhzChan;
177 if (flags & IEEE80211_CHAN_2GHZ) {
178 *low = pCap->halLow2GhzChan;
179 *high = pCap->halHigh2GhzChan;
186 getWirelessModes(struct ath_hal *ah)
193 mode |= HAL_MODE_TURBO;
196 mode |= HAL_MODE_11B;
198 mode |= HAL_MODE_11G;
200 mode |= HAL_MODE_108G;
203 mode |= HAL_MODE_11NG_HT20|HAL_MODE_11NA_HT20;
205 mode |= HAL_MODE_11NG_HT40PLUS|HAL_MODE_11NA_HT40PLUS
206 | HAL_MODE_11NG_HT40MINUS|HAL_MODE_11NA_HT40MINUS
211 /* Enumerated Regulatory Domain Information 8 bit values indicate that
212 * the regdomain is really a pair of unitary regdomains. 12 bit values
213 * are the real unitary regdomains and are the only ones which have the
214 * frequency bitmasks and flags set.
219 * The following regulatory domain definitions are
220 * found in the EEPROM. Each regulatory domain
221 * can operate in either a 5GHz or 2.4GHz wireless mode or
222 * both 5GHz and 2.4GHz wireless modes.
223 * In general, the value holds no special
224 * meaning and is used to decode into either specific
225 * 2.4GHz or 5GHz wireless mode for that particular
229 NULL1_WORLD = 0x03, /* For 11b-only countries (no 11a allowed) */
230 NULL1_ETSIB = 0x07, /* Israel */
232 FCC1_FCCA = 0x10, /* USA */
233 FCC1_WORLD = 0x11, /* Hong Kong */
234 FCC4_FCCA = 0x12, /* USA - Public Safety */
236 FCC2_FCCA = 0x20, /* Canada */
237 FCC2_WORLD = 0x21, /* Australia & HK */
239 FRANCE_RES = 0x31, /* Legacy France for OEM */
240 FCC3_FCCA = 0x3A, /* USA & Canada w/5470 band, 11h, DFS enabled */
241 FCC3_WORLD = 0x3B, /* USA & Canada w/5470 band, 11h, DFS enabled */
244 ETSI3_ETSIA = 0x32, /* France (optional) */
245 ETSI2_WORLD = 0x35, /* Hungary & others */
246 ETSI3_WORLD = 0x36, /* France & others */
250 ETSI6_WORLD = 0x34, /* Bulgaria */
251 ETSI_RESERVED = 0x33, /* Reserved (Do not used) */
253 MKK1_MKKA = 0x40, /* Japan (JP1) */
254 MKK1_MKKB = 0x41, /* Japan (JP0) */
255 APL4_WORLD = 0x42, /* Singapore */
256 MKK2_MKKA = 0x43, /* Japan with 4.9G channels */
257 APL_RESERVED = 0x44, /* Reserved (Do not used) */
258 APL2_WORLD = 0x45, /* Korea */
261 MKK1_FCCA = 0x48, /* Japan (JP1-1) */
262 APL2_APLD = 0x49, /* Korea with 2.3G channels */
263 MKK1_MKKA1 = 0x4A, /* Japan (JE1) */
264 MKK1_MKKA2 = 0x4B, /* Japan (JE2) */
265 MKK1_MKKC = 0x4C, /* Japan (MKK1_MKKA,except Ch14) */
268 APL1_WORLD = 0x52, /* Latin America */
272 APL2_ETSIC = 0x56, /* Venezuela */
273 APL5_WORLD = 0x58, /* Chile */
274 APL6_WORLD = 0x5B, /* Singapore */
275 APL7_FCCA = 0x5C, /* Taiwan 5.47 Band */
276 APL8_WORLD = 0x5D, /* Malaysia 5GHz */
277 APL9_WORLD = 0x5E, /* Korea 5GHz */
282 WOR0_WORLD = 0x60, /* World0 (WO0 SKU) */
283 WOR1_WORLD = 0x61, /* World1 (WO1 SKU) */
284 WOR2_WORLD = 0x62, /* World2 (WO2 SKU) */
285 WOR3_WORLD = 0x63, /* World3 (WO3 SKU) */
286 WOR4_WORLD = 0x64, /* World4 (WO4 SKU) */
287 WOR5_ETSIC = 0x65, /* World5 (WO5 SKU) */
289 WOR01_WORLD = 0x66, /* World0-1 (WW0-1 SKU) */
290 WOR02_WORLD = 0x67, /* World0-2 (WW0-2 SKU) */
291 EU1_WORLD = 0x68, /* Same as World0-2 (WW0-2 SKU), except active scan ch1-13. No ch14 */
293 WOR9_WORLD = 0x69, /* World9 (WO9 SKU) */
294 WORA_WORLD = 0x6A, /* WorldA (WOA SKU) */
296 MKK3_MKKB = 0x80, /* Japan UNI-1 even + MKKB */
297 MKK3_MKKA2 = 0x81, /* Japan UNI-1 even + MKKA2 */
298 MKK3_MKKC = 0x82, /* Japan UNI-1 even + MKKC */
300 MKK4_MKKB = 0x83, /* Japan UNI-1 even + UNI-2 + MKKB */
301 MKK4_MKKA2 = 0x84, /* Japan UNI-1 even + UNI-2 + MKKA2 */
302 MKK4_MKKC = 0x85, /* Japan UNI-1 even + UNI-2 + MKKC */
304 MKK5_MKKB = 0x86, /* Japan UNI-1 even + UNI-2 + mid-band + MKKB */
305 MKK5_MKKA2 = 0x87, /* Japan UNI-1 even + UNI-2 + mid-band + MKKA2 */
306 MKK5_MKKC = 0x88, /* Japan UNI-1 even + UNI-2 + mid-band + MKKC */
308 MKK6_MKKB = 0x89, /* Japan UNI-1 even + UNI-1 odd MKKB */
309 MKK6_MKKA2 = 0x8A, /* Japan UNI-1 even + UNI-1 odd + MKKA2 */
310 MKK6_MKKC = 0x8B, /* Japan UNI-1 even + UNI-1 odd + MKKC */
312 MKK7_MKKB = 0x8C, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKB */
313 MKK7_MKKA2 = 0x8D, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKA2 */
314 MKK7_MKKC = 0x8E, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKC */
316 MKK8_MKKB = 0x8F, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKB */
317 MKK8_MKKA2 = 0x90, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKA2 */
318 MKK8_MKKC = 0x91, /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKC */
320 /* Following definitions are used only by s/w to map old
323 MKK3_MKKA = 0xF0, /* Japan UNI-1 even + MKKA */
324 MKK3_MKKA1 = 0xF1, /* Japan UNI-1 even + MKKA1 */
325 MKK3_FCCA = 0xF2, /* Japan UNI-1 even + FCCA */
326 MKK4_MKKA = 0xF3, /* Japan UNI-1 even + UNI-2 + MKKA */
327 MKK4_MKKA1 = 0xF4, /* Japan UNI-1 even + UNI-2 + MKKA1 */
328 MKK4_FCCA = 0xF5, /* Japan UNI-1 even + UNI-2 + FCCA */
329 MKK9_MKKA = 0xF6, /* Japan UNI-1 even + 4.9GHz */
330 MKK10_MKKA = 0xF7, /* Japan UNI-1 even + UNI-2 + 4.9GHz */
333 * Regulator domains ending in a number (e.g. APL1,
334 * MK1, ETSI4, etc) apply to 5GHz channel and power
335 * information. Regulator domains ending in a letter
336 * (e.g. APLA, FCCA, etc) apply to 2.4GHz channel and
339 APL1 = 0x0150, /* LAT & Asia */
340 APL2 = 0x0250, /* LAT & Asia */
341 APL3 = 0x0350, /* Taiwan */
342 APL4 = 0x0450, /* Jordan */
343 APL5 = 0x0550, /* Chile */
344 APL6 = 0x0650, /* Singapore */
345 APL8 = 0x0850, /* Malaysia */
346 APL9 = 0x0950, /* Korea (South) ROC 3 */
348 ETSI1 = 0x0130, /* Europe & others */
349 ETSI2 = 0x0230, /* Europe & others */
350 ETSI3 = 0x0330, /* Europe & others */
351 ETSI4 = 0x0430, /* Europe & others */
352 ETSI5 = 0x0530, /* Europe & others */
353 ETSI6 = 0x0630, /* Europe & others */
354 ETSIA = 0x0A30, /* France */
355 ETSIB = 0x0B30, /* Israel */
356 ETSIC = 0x0C30, /* Latin America */
358 FCC1 = 0x0110, /* US & others */
359 FCC2 = 0x0120, /* Canada, Australia & New Zealand */
360 FCC3 = 0x0160, /* US w/new middle band & DFS */
361 FCC4 = 0x0165, /* US Public Safety */
364 APLD = 0x0D50, /* South Korea */
366 MKK1 = 0x0140, /* Japan (UNI-1 odd)*/
367 MKK2 = 0x0240, /* Japan (4.9 GHz + UNI-1 odd) */
368 MKK3 = 0x0340, /* Japan (UNI-1 even) */
369 MKK4 = 0x0440, /* Japan (UNI-1 even + UNI-2) */
370 MKK5 = 0x0540, /* Japan (UNI-1 even + UNI-2 + mid-band) */
371 MKK6 = 0x0640, /* Japan (UNI-1 odd + UNI-1 even) */
372 MKK7 = 0x0740, /* Japan (UNI-1 odd + UNI-1 even + UNI-2 */
373 MKK8 = 0x0840, /* Japan (UNI-1 odd + UNI-1 even + UNI-2 + mid-band) */
374 MKK9 = 0x0940, /* Japan (UNI-1 even + 4.9 GHZ) */
375 MKK10 = 0x0B40, /* Japan (UNI-1 even + UNI-2 + 4.9 GHZ) */
376 MKKA = 0x0A40, /* Japan */
381 DEBUG_REG_DMN = 0x01ff,
383 #define DEF_REGDMN FCC1_FCCA
389 #define D(_x) { #_x, _x }
391 D(NULL1_WORLD), /* For 11b-only countries (no 11a allowed) */
392 D(NULL1_ETSIB), /* Israel */
394 D(FCC1_FCCA), /* USA */
395 D(FCC1_WORLD), /* Hong Kong */
396 D(FCC4_FCCA), /* USA - Public Safety */
398 D(FCC2_FCCA), /* Canada */
399 D(FCC2_WORLD), /* Australia & HK */
401 D(FRANCE_RES), /* Legacy France for OEM */
406 D(ETSI3_ETSIA), /* France (optional) */
407 D(ETSI2_WORLD), /* Hungary & others */
408 D(ETSI3_WORLD), /* France & others */
412 D(ETSI6_WORLD), /* Bulgaria */
413 D(ETSI_RESERVED), /* Reserved (Do not used) */
415 D(MKK1_MKKA), /* Japan (JP1) */
416 D(MKK1_MKKB), /* Japan (JP0) */
417 D(APL4_WORLD), /* Singapore */
418 D(MKK2_MKKA), /* Japan with 4.9G channels */
419 D(APL_RESERVED), /* Reserved (Do not used) */
420 D(APL2_WORLD), /* Korea */
423 D(MKK1_FCCA), /* Japan (JP1-1) */
424 D(APL2_APLD), /* Korea with 2.3G channels */
425 D(MKK1_MKKA1), /* Japan (JE1) */
426 D(MKK1_MKKA2), /* Japan (JE2) */
430 D(APL1_WORLD), /* Latin America */
434 D(APL2_ETSIC), /* Venezuela */
435 D(APL5_WORLD), /* Chile */
436 D(APL6_WORLD), /* Singapore */
437 D(APL7_FCCA), /* Taiwan 5.47 Band */
438 D(APL8_WORLD), /* Malaysia 5GHz */
439 D(APL9_WORLD), /* Korea 5GHz */
441 D(WOR0_WORLD), /* World0 (WO0 SKU) */
442 D(WOR1_WORLD), /* World1 (WO1 SKU) */
443 D(WOR2_WORLD), /* World2 (WO2 SKU) */
444 D(WOR3_WORLD), /* World3 (WO3 SKU) */
445 D(WOR4_WORLD), /* World4 (WO4 SKU) */
446 D(WOR5_ETSIC), /* World5 (WO5 SKU) */
448 D(WOR01_WORLD), /* World0-1 (WW0-1 SKU) */
449 D(WOR02_WORLD), /* World0-2 (WW0-2 SKU) */
452 D(WOR9_WORLD), /* World9 (WO9 SKU) */
453 D(WORA_WORLD), /* WorldA (WOA SKU) */
455 D(MKK3_MKKB), /* Japan UNI-1 even + MKKB */
456 D(MKK3_MKKA2), /* Japan UNI-1 even + MKKA2 */
457 D(MKK3_MKKC), /* Japan UNI-1 even + MKKC */
459 D(MKK4_MKKB), /* Japan UNI-1 even + UNI-2 + MKKB */
460 D(MKK4_MKKA2), /* Japan UNI-1 even + UNI-2 + MKKA2 */
461 D(MKK4_MKKC), /* Japan UNI-1 even + UNI-2 + MKKC */
463 D(MKK5_MKKB), /* Japan UNI-1 even + UNI-2 + mid-band + MKKB */
464 D(MKK5_MKKA2), /* Japan UNI-1 even + UNI-2 + mid-band + MKKA2 */
465 D(MKK5_MKKC), /* Japan UNI-1 even + UNI-2 + mid-band + MKKC */
467 D(MKK6_MKKB), /* Japan UNI-1 even + UNI-1 odd MKKB */
468 D(MKK6_MKKA2), /* Japan UNI-1 even + UNI-1 odd + MKKA2 */
469 D(MKK6_MKKC), /* Japan UNI-1 even + UNI-1 odd + MKKC */
471 D(MKK7_MKKB), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKB */
472 D(MKK7_MKKA2), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKA2 */
473 D(MKK7_MKKC), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + MKKC */
475 D(MKK8_MKKB), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKB */
476 D(MKK8_MKKA2), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKA2 */
477 D(MKK8_MKKC), /* Japan UNI-1 even + UNI-1 odd + UNI-2 + mid-band + MKKC */
479 D(MKK3_MKKA), /* Japan UNI-1 even + MKKA */
480 D(MKK3_MKKA1), /* Japan UNI-1 even + MKKA1 */
481 D(MKK3_FCCA), /* Japan UNI-1 even + FCCA */
482 D(MKK4_MKKA), /* Japan UNI-1 even + UNI-2 + MKKA */
483 D(MKK4_MKKA1), /* Japan UNI-1 even + UNI-2 + MKKA1 */
484 D(MKK4_FCCA), /* Japan UNI-1 even + UNI-2 + FCCA */
485 D(MKK9_MKKA), /* Japan UNI-1 even + 4.9GHz */
486 D(MKK10_MKKA), /* Japan UNI-1 even + UNI-2 + 4.9GHz */
488 D(APL1), /* LAT & Asia */
489 D(APL2), /* LAT & Asia */
490 D(APL3), /* Taiwan */
491 D(APL4), /* Jordan */
493 D(APL6), /* Singapore */
494 D(APL8), /* Malaysia */
495 D(APL9), /* Korea (South) ROC 3 */
497 D(ETSI1), /* Europe & others */
498 D(ETSI2), /* Europe & others */
499 D(ETSI3), /* Europe & others */
500 D(ETSI4), /* Europe & others */
501 D(ETSI5), /* Europe & others */
502 D(ETSI6), /* Europe & others */
503 D(ETSIA), /* France */
504 D(ETSIB), /* Israel */
505 D(ETSIC), /* Latin America */
507 D(FCC1), /* US & others */
509 D(FCC3), /* US w/new middle band & DFS */
510 D(FCC4), /* US Public Safety */
513 D(APLD), /* South Korea */
515 D(MKK1), /* Japan (UNI-1 odd)*/
516 D(MKK2), /* Japan (4.9 GHz + UNI-1 odd) */
517 D(MKK3), /* Japan (UNI-1 even) */
518 D(MKK4), /* Japan (UNI-1 even + UNI-2) */
519 D(MKK5), /* Japan (UNI-1 even + UNI-2 + mid-band) */
520 D(MKK6), /* Japan (UNI-1 odd + UNI-1 even) */
521 D(MKK7), /* Japan (UNI-1 odd + UNI-1 even + UNI-2 */
522 D(MKK8), /* Japan (UNI-1 odd + UNI-1 even + UNI-2 + mid-band) */
523 D(MKK9), /* Japan (UNI-1 even + 4.9 GHZ) */
524 D(MKK10), /* Japan (UNI-1 even + UNI-2 + 4.9 GHZ) */
535 rdlookup(const char *name, HAL_REG_DOMAIN *rd)
537 #define N(a) (sizeof(a)/sizeof(a[0]))
540 for (i = 0; i < N(domains); i++)
541 if (strcasecmp(domains[i].name, name) == 0) {
550 getrdname(HAL_REG_DOMAIN rd)
552 #define N(a) (sizeof(a)/sizeof(a[0]))
555 for (i = 0; i < N(domains); i++)
556 if (domains[i].rd == rd)
557 return domains[i].name;
565 #define N(a) (sizeof(a)/sizeof(a[0]))
568 printf("\nRegulatory domains:\n\n");
569 for (i = 0; i < N(domains); i++)
570 printf("%-15s%s", domains[i].name,
571 ((i+1)%5) == 0 ? "\n" : "");
577 HAL_CTRY_CODE countryCode;
578 HAL_REG_DOMAIN regDmnEnum;
581 } COUNTRY_CODE_TO_ENUM_RD;
584 * Country Code Table to Enumerated RD
586 static COUNTRY_CODE_TO_ENUM_RD allCountries[] = {
587 {CTRY_DEBUG, NO_ENUMRD, "DB", "DEBUG" },
588 {CTRY_DEFAULT, DEF_REGDMN, "NA", "NO_COUNTRY_SET" },
589 {CTRY_ALBANIA, NULL1_WORLD, "AL", "ALBANIA" },
590 {CTRY_ALGERIA, NULL1_WORLD, "DZ", "ALGERIA" },
591 {CTRY_ARGENTINA, APL3_WORLD, "AR", "ARGENTINA" },
592 {CTRY_ARMENIA, ETSI4_WORLD, "AM", "ARMENIA" },
593 {CTRY_AUSTRALIA, FCC2_WORLD, "AU", "AUSTRALIA" },
594 {CTRY_AUSTRIA, ETSI1_WORLD, "AT", "AUSTRIA" },
595 {CTRY_AZERBAIJAN, ETSI4_WORLD, "AZ", "AZERBAIJAN" },
596 {CTRY_BAHRAIN, APL6_WORLD, "BH", "BAHRAIN" },
597 {CTRY_BELARUS, NULL1_WORLD, "BY", "BELARUS" },
598 {CTRY_BELGIUM, ETSI1_WORLD, "BE", "BELGIUM" },
599 {CTRY_BELIZE, APL1_ETSIC, "BZ", "BELIZE" },
600 {CTRY_BOLIVIA, APL1_ETSIC, "BO", "BOLVIA" },
601 {CTRY_BRAZIL, FCC3_WORLD, "BR", "BRAZIL" },
602 {CTRY_BRUNEI_DARUSSALAM,APL1_WORLD,"BN", "BRUNEI DARUSSALAM" },
603 {CTRY_BULGARIA, ETSI6_WORLD, "BG", "BULGARIA" },
604 {CTRY_CANADA, FCC2_FCCA, "CA", "CANADA" },
605 {CTRY_CHILE, APL6_WORLD, "CL", "CHILE" },
606 {CTRY_CHINA, APL1_WORLD, "CN", "CHINA" },
607 {CTRY_COLOMBIA, FCC1_FCCA, "CO", "COLOMBIA" },
608 {CTRY_COSTA_RICA, NULL1_WORLD, "CR", "COSTA RICA" },
609 {CTRY_CROATIA, ETSI3_WORLD, "HR", "CROATIA" },
610 {CTRY_CYPRUS, ETSI1_WORLD, "CY", "CYPRUS" },
611 {CTRY_CZECH, ETSI3_WORLD, "CZ", "CZECH REPUBLIC" },
612 {CTRY_DENMARK, ETSI1_WORLD, "DK", "DENMARK" },
613 {CTRY_DOMINICAN_REPUBLIC,FCC1_FCCA,"DO", "DOMINICAN REPUBLIC" },
614 {CTRY_ECUADOR, NULL1_WORLD, "EC", "ECUADOR" },
615 {CTRY_EGYPT, ETSI3_WORLD, "EG", "EGYPT" },
616 {CTRY_EL_SALVADOR, NULL1_WORLD, "SV", "EL SALVADOR" },
617 {CTRY_ESTONIA, ETSI1_WORLD, "EE", "ESTONIA" },
618 {CTRY_FINLAND, ETSI1_WORLD, "FI", "FINLAND" },
619 {CTRY_FRANCE, ETSI3_WORLD, "FR", "FRANCE" },
620 {CTRY_FRANCE2, ETSI3_WORLD, "F2", "FRANCE_RES" },
621 {CTRY_GEORGIA, ETSI4_WORLD, "GE", "GEORGIA" },
622 {CTRY_GERMANY, ETSI1_WORLD, "DE", "GERMANY" },
623 {CTRY_GREECE, ETSI1_WORLD, "GR", "GREECE" },
624 {CTRY_GUATEMALA, FCC1_FCCA, "GT", "GUATEMALA" },
625 {CTRY_HONDURAS, NULL1_WORLD, "HN", "HONDURAS" },
626 {CTRY_HONG_KONG, FCC2_WORLD, "HK", "HONG KONG" },
627 {CTRY_HUNGARY, ETSI1_WORLD, "HU", "HUNGARY" },
628 {CTRY_ICELAND, ETSI1_WORLD, "IS", "ICELAND" },
629 {CTRY_INDIA, APL6_WORLD, "IN", "INDIA" },
630 {CTRY_INDONESIA, APL1_WORLD, "ID", "INDONESIA" },
631 {CTRY_IRAN, APL1_WORLD, "IR", "IRAN" },
632 {CTRY_IRELAND, ETSI1_WORLD, "IE", "IRELAND" },
633 {CTRY_ISRAEL, NULL1_WORLD, "IL", "ISRAEL" },
634 {CTRY_ITALY, ETSI1_WORLD, "IT", "ITALY" },
635 {CTRY_JAPAN, MKK1_MKKA, "JP", "JAPAN" },
636 {CTRY_JAPAN1, MKK1_MKKB, "JP", "JAPAN1" },
637 {CTRY_JAPAN2, MKK1_FCCA, "JP", "JAPAN2" },
638 {CTRY_JAPAN3, MKK2_MKKA, "JP", "JAPAN3" },
639 {CTRY_JAPAN4, MKK1_MKKA1, "JP", "JAPAN4" },
640 {CTRY_JAPAN5, MKK1_MKKA2, "JP", "JAPAN5" },
641 {CTRY_JAPAN6, MKK1_MKKC, "JP", "JAPAN6" },
643 {CTRY_JAPAN7, MKK3_MKKB, "JP", "JAPAN7" },
644 {CTRY_JAPAN8, MKK3_MKKA2, "JP", "JAPAN8" },
645 {CTRY_JAPAN9, MKK3_MKKC, "JP", "JAPAN9" },
647 {CTRY_JAPAN10, MKK4_MKKB, "JP", "JAPAN10" },
648 {CTRY_JAPAN11, MKK4_MKKA2, "JP", "JAPAN11" },
649 {CTRY_JAPAN12, MKK4_MKKC, "JP", "JAPAN12" },
651 {CTRY_JAPAN13, MKK5_MKKB, "JP", "JAPAN13" },
652 {CTRY_JAPAN14, MKK5_MKKA2, "JP", "JAPAN14" },
653 {CTRY_JAPAN15, MKK5_MKKC, "JP", "JAPAN15" },
655 {CTRY_JAPAN16, MKK6_MKKB, "JP", "JAPAN16" },
656 {CTRY_JAPAN17, MKK6_MKKA2, "JP", "JAPAN17" },
657 {CTRY_JAPAN18, MKK6_MKKC, "JP", "JAPAN18" },
659 {CTRY_JAPAN19, MKK7_MKKB, "JP", "JAPAN19" },
660 {CTRY_JAPAN20, MKK7_MKKA2, "JP", "JAPAN20" },
661 {CTRY_JAPAN21, MKK7_MKKC, "JP", "JAPAN21" },
663 {CTRY_JAPAN22, MKK8_MKKB, "JP", "JAPAN22" },
664 {CTRY_JAPAN23, MKK8_MKKA2, "JP", "JAPAN23" },
665 {CTRY_JAPAN24, MKK8_MKKC, "JP", "JAPAN24" },
667 {CTRY_JORDAN, APL4_WORLD, "JO", "JORDAN" },
668 {CTRY_KAZAKHSTAN, NULL1_WORLD, "KZ", "KAZAKHSTAN" },
669 {CTRY_KOREA_NORTH, APL2_WORLD, "KP", "NORTH KOREA" },
670 {CTRY_KOREA_ROC, APL2_WORLD, "KR", "KOREA REPUBLIC" },
671 {CTRY_KOREA_ROC2, APL2_WORLD, "K2", "KOREA REPUBLIC2" },
672 {CTRY_KOREA_ROC3, APL9_WORLD, "K3", "KOREA REPUBLIC3" },
673 {CTRY_KUWAIT, NULL1_WORLD, "KW", "KUWAIT" },
674 {CTRY_LATVIA, ETSI1_WORLD, "LV", "LATVIA" },
675 {CTRY_LEBANON, NULL1_WORLD, "LB", "LEBANON" },
676 {CTRY_LIECHTENSTEIN,ETSI1_WORLD, "LI", "LIECHTENSTEIN" },
677 {CTRY_LITHUANIA, ETSI1_WORLD, "LT", "LITHUANIA" },
678 {CTRY_LUXEMBOURG, ETSI1_WORLD, "LU", "LUXEMBOURG" },
679 {CTRY_MACAU, FCC2_WORLD, "MO", "MACAU" },
680 {CTRY_MACEDONIA, NULL1_WORLD, "MK", "MACEDONIA" },
681 {CTRY_MALAYSIA, APL8_WORLD, "MY", "MALAYSIA" },
682 {CTRY_MALTA, ETSI1_WORLD, "MT", "MALTA" },
683 {CTRY_MEXICO, FCC1_FCCA, "MX", "MEXICO" },
684 {CTRY_MONACO, ETSI4_WORLD, "MC", "MONACO" },
685 {CTRY_MOROCCO, NULL1_WORLD, "MA", "MOROCCO" },
686 {CTRY_NETHERLANDS, ETSI1_WORLD, "NL", "NETHERLANDS" },
687 {CTRY_NEW_ZEALAND, FCC2_ETSIC, "NZ", "NEW ZEALAND" },
688 {CTRY_NORWAY, ETSI1_WORLD, "NO", "NORWAY" },
689 {CTRY_OMAN, APL6_WORLD, "OM", "OMAN" },
690 {CTRY_PAKISTAN, NULL1_WORLD, "PK", "PAKISTAN" },
691 {CTRY_PANAMA, FCC1_FCCA, "PA", "PANAMA" },
692 {CTRY_PERU, APL1_WORLD, "PE", "PERU" },
693 {CTRY_PHILIPPINES, APL1_WORLD, "PH", "PHILIPPINES" },
694 {CTRY_POLAND, ETSI1_WORLD, "PL", "POLAND" },
695 {CTRY_PORTUGAL, ETSI1_WORLD, "PT", "PORTUGAL" },
696 {CTRY_PUERTO_RICO, FCC1_FCCA, "PR", "PUERTO RICO" },
697 {CTRY_QATAR, NULL1_WORLD, "QA", "QATAR" },
698 {CTRY_ROMANIA, NULL1_WORLD, "RO", "ROMANIA" },
699 {CTRY_RUSSIA, NULL1_WORLD, "RU", "RUSSIA" },
700 {CTRY_SAUDI_ARABIA,NULL1_WORLD, "SA", "SAUDI ARABIA" },
701 {CTRY_SINGAPORE, APL6_WORLD, "SG", "SINGAPORE" },
702 {CTRY_SLOVAKIA, ETSI1_WORLD, "SK", "SLOVAK REPUBLIC" },
703 {CTRY_SLOVENIA, ETSI1_WORLD, "SI", "SLOVENIA" },
704 {CTRY_SOUTH_AFRICA,FCC3_WORLD, "ZA", "SOUTH AFRICA" },
705 {CTRY_SPAIN, ETSI1_WORLD, "ES", "SPAIN" },
706 {CTRY_SWEDEN, ETSI1_WORLD, "SE", "SWEDEN" },
707 {CTRY_SWITZERLAND, ETSI1_WORLD, "CH", "SWITZERLAND" },
708 {CTRY_SYRIA, NULL1_WORLD, "SY", "SYRIA" },
709 {CTRY_TAIWAN, APL3_FCCA, "TW", "TAIWAN" },
710 {CTRY_THAILAND, NULL1_WORLD, "TH", "THAILAND" },
711 {CTRY_TRINIDAD_Y_TOBAGO,ETSI4_WORLD,"TT", "TRINIDAD & TOBAGO" },
712 {CTRY_TUNISIA, ETSI3_WORLD, "TN", "TUNISIA" },
713 {CTRY_TURKEY, ETSI3_WORLD, "TR", "TURKEY" },
714 {CTRY_UKRAINE, NULL1_WORLD, "UA", "UKRAINE" },
715 {CTRY_UAE, NULL1_WORLD, "AE", "UNITED ARAB EMIRATES" },
716 {CTRY_UNITED_KINGDOM, ETSI1_WORLD,"GB", "UNITED KINGDOM" },
717 {CTRY_UNITED_STATES, FCC1_FCCA, "US", "UNITED STATES" },
718 {CTRY_UNITED_STATES_FCC49, FCC4_FCCA, "PS", "UNITED STATES (PUBLIC SAFETY)" },
719 {CTRY_URUGUAY, APL2_WORLD, "UY", "URUGUAY" },
720 {CTRY_UZBEKISTAN, FCC3_FCCA, "UZ", "UZBEKISTAN" },
721 {CTRY_VENEZUELA, APL2_ETSIC, "VE", "VENEZUELA" },
722 {CTRY_VIET_NAM, NULL1_WORLD, "VN", "VIET NAM" },
723 {CTRY_YEMEN, NULL1_WORLD, "YE", "YEMEN" },
724 {CTRY_ZIMBABWE, NULL1_WORLD, "ZW", "ZIMBABWE" }
728 cclookup(const char *name, HAL_REG_DOMAIN *rd, HAL_CTRY_CODE *cc)
730 #define N(a) (sizeof(a)/sizeof(a[0]))
733 for (i = 0; i < N(allCountries); i++)
734 if (strcasecmp(allCountries[i].isoName, name) == 0 ||
735 strcasecmp(allCountries[i].name, name) == 0) {
736 *rd = allCountries[i].regDmnEnum;
737 *cc = allCountries[i].countryCode;
745 getccname(HAL_CTRY_CODE cc)
747 #define N(a) (sizeof(a)/sizeof(a[0]))
750 for (i = 0; i < N(allCountries); i++)
751 if (allCountries[i].countryCode == cc)
752 return allCountries[i].name;
758 getccisoname(HAL_CTRY_CODE cc)
760 #define N(a) (sizeof(a)/sizeof(a[0]))
763 for (i = 0; i < N(allCountries); i++)
764 if (allCountries[i].countryCode == cc)
765 return allCountries[i].isoName;
773 #define N(a) (sizeof(a)/sizeof(a[0]))
776 printf("\nCountry codes:\n");
777 for (i = 0; i < N(allCountries); i++)
778 printf("%2s %-15.15s%s",
779 allCountries[i].isoName,
780 allCountries[i].name,
781 ((i+1)%4) == 0 ? "\n" : " ");
787 setRateTable(struct ath_hal *ah, const struct ieee80211_channel *chan,
788 int16_t tpcScaleReduction, int16_t powerLimit,
789 int16_t *pMinPower, int16_t *pMaxPower);
792 calctxpower(struct ath_hal *ah,
793 int nchan, const struct ieee80211_channel *chans,
794 int16_t tpcScaleReduction, int16_t powerLimit, int16_t *txpow)
799 for (i = 0; i < nchan; i++)
800 if (!setRateTable(ah, &chans[i],
801 tpcScaleReduction, powerLimit, &minpow, &txpow[i])) {
802 printf("unable to set rate table\n");
808 const char *sep = "";
810 int showchannels = 0;
815 anychan(const struct ieee80211_channel *chans, int nc, int flag)
819 for (i = 0; i < nc; i++)
820 if ((chans[i].ic_flags & flag) != 0)
826 mapgsm(u_int freq, u_int flags)
829 if (flags & IEEE80211_CHAN_QUARTER)
831 else if (flags & IEEE80211_CHAN_HALF)
835 return (freq - 24220) / 5;
839 mappsb(u_int freq, u_int flags)
841 return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
845 * Convert GHz frequency to IEEE channel number.
848 ath_hal_mhz2ieee(struct ath_hal *ah, u_int freq, u_int flags)
850 if (flags & IEEE80211_CHAN_2GHZ) { /* 2GHz band */
854 return ((int)freq - 2407) / 5;
856 return 15 + ((freq - 2512) / 20);
857 } else if (flags & IEEE80211_CHAN_5GHZ) {/* 5Ghz band */
858 if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq))
859 return mappsb(freq, flags);
860 else if ((flags & IEEE80211_CHAN_A) && (freq <= 5000))
861 return (freq - 4000) / 5;
863 return (freq - 5000) / 5;
864 } else { /* either, guess */
868 return ((int)freq - 2407) / 5;
870 if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq))
871 return mappsb(freq, flags);
872 else if (freq > 4900)
873 return (freq - 4000) / 5;
875 return 15 + ((freq - 2512) / 20);
877 return (freq - 5000) / 5;
881 #define IEEE80211_IS_CHAN_4MS(_c) \
882 (((_c)->ic_flags & IEEE80211_CHAN_4MSXMIT) != 0)
885 dumpchannels(struct ath_hal *ah, int nc,
886 const struct ieee80211_channel *chans, int16_t *txpow)
890 for (i = 0; i < nc; i++) {
891 const struct ieee80211_channel *c = &chans[i];
896 ath_hal_mhz2ieee(ah, c->ic_freq, c->ic_flags));
898 printf("%s%u", sep, c->ic_freq);
899 if (IEEE80211_IS_CHAN_HALF(c))
901 else if (IEEE80211_IS_CHAN_QUARTER(c))
903 else if (IEEE80211_IS_CHAN_TURBO(c))
905 else if (IEEE80211_IS_CHAN_HT(c))
907 else if (IEEE80211_IS_CHAN_A(c))
909 else if (IEEE80211_IS_CHAN_108G(c))
911 else if (IEEE80211_IS_CHAN_G(c))
915 if (dopassive && IEEE80211_IS_CHAN_PASSIVE(c))
916 type = tolower(type);
918 printf("%c%c%c %d.%d", type,
919 IEEE80211_IS_CHAN_DFS(c) ? '*' : ' ',
920 IEEE80211_IS_CHAN_4MS(c) ? '4' : ' ',
921 txpow[i]/2, (txpow[i]%2)*5);
923 printf("%c%c %d.%d", type,
924 IEEE80211_IS_CHAN_DFS(c) ? '*' : ' ',
925 txpow[i]/2, (txpow[i]%2)*5);
927 printf("%c%c %d.%d", type,
928 IEEE80211_IS_CHAN_4MS(c) ? '4' : ' ',
929 txpow[i]/2, (txpow[i]%2)*5);
931 printf("%c %d.%d", type, txpow[i]/2, (txpow[i]%2)*5);
932 if ((n++ % (showchannels ? 7 : 6)) == 0)
940 intersect(struct ieee80211_channel *dst, int16_t *dtxpow, int *nd,
941 const struct ieee80211_channel *src, int16_t *stxpow, int ns)
945 for (j = 0; j < ns && dst[i].ic_freq != src[j].ic_freq; j++)
947 if (j < ns && dtxpow[i] == stxpow[j]) {
948 for (k = i+1, l = i; k < *nd; k++, l++)
957 usage(const char *progname)
959 printf("usage: %s [-acdefoilpr4ABGT] [-m opmode] [cc | rd]\n", progname);
964 getChipPowerLimits(struct ath_hal *ah, struct ieee80211_channel *chan)
969 eepromRead(struct ath_hal *ah, u_int off, u_int16_t *data)
971 /* emulate enough stuff to handle japan channel shift */
973 case AR_EEPROM_VERSION:
976 case AR_EEPROM_REG_CAPABILITIES_OFFSET:
977 *data = AR_EEPROM_EEREGCAP_EN_KK_NEW_11A;
979 case AR_EEPROM_REG_CAPABILITIES_OFFSET_PRE4_0:
980 *data = AR_EEPROM_EEREGCAP_EN_KK_NEW_11A_PRE4_0;
987 getCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
988 uint32_t capability, uint32_t *result)
990 const HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
993 case HAL_CAP_REG_DMN: /* regulatory domain */
994 *result = AH_PRIVATE(ah)->ah_currentRD;
1001 #define HAL_MODE_HT20 \
1002 (HAL_MODE_11NG_HT20 | HAL_MODE_11NA_HT20)
1003 #define HAL_MODE_HT40 \
1004 (HAL_MODE_11NG_HT40PLUS | HAL_MODE_11NG_HT40MINUS | \
1005 HAL_MODE_11NA_HT40PLUS | HAL_MODE_11NA_HT40MINUS)
1006 #define HAL_MODE_HT (HAL_MODE_HT20 | HAL_MODE_HT40)
1009 main(int argc, char *argv[])
1011 static const u_int16_t tpcScaleReductionTable[5] =
1012 { 0, 3, 6, 9, MAX_RATE_POWER };
1013 struct ath_hal_private ahp;
1014 struct ieee80211_channel achans[IEEE80211_CHAN_MAX];
1015 int16_t atxpow[IEEE80211_CHAN_MAX];
1016 struct ieee80211_channel bchans[IEEE80211_CHAN_MAX];
1017 int16_t btxpow[IEEE80211_CHAN_MAX];
1018 struct ieee80211_channel gchans[IEEE80211_CHAN_MAX];
1019 int16_t gtxpow[IEEE80211_CHAN_MAX];
1020 struct ieee80211_channel tchans[IEEE80211_CHAN_MAX];
1021 int16_t ttxpow[IEEE80211_CHAN_MAX];
1022 struct ieee80211_channel tgchans[IEEE80211_CHAN_MAX];
1023 int16_t tgtxpow[IEEE80211_CHAN_MAX];
1024 struct ieee80211_channel nchans[IEEE80211_CHAN_MAX];
1025 int16_t ntxpow[IEEE80211_CHAN_MAX];
1026 int i, na, nb, ng, nt, ntg, nn;
1027 HAL_BOOL showall = AH_FALSE;
1028 HAL_BOOL extendedChanMode = AH_TRUE;
1030 int16_t tpcReduction, powerLimit;
1034 memset(&ahp, 0, sizeof(ahp));
1035 ahp.ah_getChannelEdges = getChannelEdges;
1036 ahp.ah_getWirelessModes = getWirelessModes;
1037 ahp.ah_eepromRead = eepromRead;
1038 ahp.ah_getChipPowerLimits = getChipPowerLimits;
1039 ahp.ah_caps.halWirelessModes = HAL_MODE_ALL;
1040 ahp.ah_caps.halLow5GhzChan = 4920;
1041 ahp.ah_caps.halHigh5GhzChan = 6100;
1042 ahp.ah_caps.halLow2GhzChan = 2312;
1043 ahp.ah_caps.halHigh2GhzChan = 2732;
1044 ahp.ah_caps.halChanHalfRate = AH_TRUE;
1045 ahp.ah_caps.halChanQuarterRate = AH_TRUE;
1046 ahp.h.ah_getCapability = getCapability;
1047 ahp.ah_opmode = HAL_M_STA;
1049 tpcReduction = tpcScaleReductionTable[0];
1050 powerLimit = MAX_RATE_POWER;
1052 while ((i = getopt(argc, argv, "acdeflm:pr4ABGhHNT")) != -1)
1058 showchannels = AH_TRUE;
1061 ath_hal_debug = HAL_DEBUG_ANY;
1064 extendedChanMode = AH_FALSE;
1067 showchannels = AH_FALSE;
1074 if (strncasecmp(optarg, "sta", 2) == 0)
1075 ahp.ah_opmode = HAL_M_STA;
1076 else if (strncasecmp(optarg, "ibss", 2) == 0)
1077 ahp.ah_opmode = HAL_M_IBSS;
1078 else if (strncasecmp(optarg, "adhoc", 2) == 0)
1079 ahp.ah_opmode = HAL_M_IBSS;
1080 else if (strncasecmp(optarg, "ap", 2) == 0)
1081 ahp.ah_opmode = HAL_M_HOSTAP;
1082 else if (strncasecmp(optarg, "hostap", 2) == 0)
1083 ahp.ah_opmode = HAL_M_HOSTAP;
1084 else if (strncasecmp(optarg, "monitor", 2) == 0)
1085 ahp.ah_opmode = HAL_M_MONITOR;
1093 modes |= HAL_MODE_11A;
1096 modes |= HAL_MODE_11B;
1099 modes |= HAL_MODE_11G;
1102 modes |= HAL_MODE_HT20;
1105 modes |= HAL_MODE_HT40;
1108 modes |= HAL_MODE_HT;
1111 modes |= HAL_MODE_TURBO | HAL_MODE_108G;
1122 switch (argc - optind) {
1124 if (!cclookup("US", &rd, &cc)) {
1125 printf("%s: unknown country code\n", "US");
1129 case 1: /* cc/regdomain */
1130 if (!cclookup(argv[optind], &rd, &cc)) {
1131 if (!rdlookup(argv[optind], &rd)) {
1134 rd = strtoul(argv[optind], NULL, 0);
1135 rdname = getrdname(rd);
1136 if (rdname == NULL) {
1137 printf("%s: unknown country/regulatory "
1138 "domain code\n", argv[optind]);
1145 default: /* regdomain cc */
1146 if (!rdlookup(argv[optind], &rd)) {
1149 rd = strtoul(argv[optind], NULL, 0);
1150 rdname = getrdname(rd);
1151 if (rdname == NULL) {
1152 printf("%s: unknown country/regulatory "
1153 "domain code\n", argv[optind]);
1157 if (!cclookup(argv[optind+1], &rd, &cc))
1158 cc = strtoul(argv[optind+1], NULL, 0);
1161 if (cc != CTRY_DEFAULT)
1162 printf("\n%s (%s, 0x%x, %u) %s (0x%x, %u)\n",
1163 getccname(cc), getccisoname(cc), cc, cc,
1164 getrdname(rd), rd, rd);
1166 printf("\n%s (0x%x, %u)\n",
1167 getrdname(rd), rd, rd);
1170 /* NB: no HAL_MODE_HT */
1171 modes = HAL_MODE_11A | HAL_MODE_11B |
1172 HAL_MODE_11G | HAL_MODE_TURBO | HAL_MODE_108G;
1174 na = nb = ng = nt = ntg = nn = 0;
1175 if (modes & HAL_MODE_11G) {
1176 ahp.ah_currentRD = rd;
1177 if (ath_hal_getchannels(&ahp.h, gchans, IEEE80211_CHAN_MAX, &ng,
1178 HAL_MODE_11G, cc, rd, extendedChanMode) == HAL_OK) {
1179 calctxpower(&ahp.h, ng, gchans, tpcReduction, powerLimit, gtxpow);
1181 isdfs |= anychan(gchans, ng, IEEE80211_CHAN_DFS);
1183 is4ms |= anychan(gchans, ng, IEEE80211_CHAN_4MSXMIT);
1186 if (modes & HAL_MODE_11B) {
1187 ahp.ah_currentRD = rd;
1188 if (ath_hal_getchannels(&ahp.h, bchans, IEEE80211_CHAN_MAX, &nb,
1189 HAL_MODE_11B, cc, rd, extendedChanMode) == HAL_OK) {
1190 calctxpower(&ahp.h, nb, bchans, tpcReduction, powerLimit, btxpow);
1192 isdfs |= anychan(bchans, nb, IEEE80211_CHAN_DFS);
1194 is4ms |= anychan(bchans, nb, IEEE80211_CHAN_4MSXMIT);
1197 if (modes & HAL_MODE_11A) {
1198 ahp.ah_currentRD = rd;
1199 if (ath_hal_getchannels(&ahp.h, achans, IEEE80211_CHAN_MAX, &na,
1200 HAL_MODE_11A, cc, rd, extendedChanMode) == HAL_OK) {
1201 calctxpower(&ahp.h, na, achans, tpcReduction, powerLimit, atxpow);
1203 isdfs |= anychan(achans, na, IEEE80211_CHAN_DFS);
1205 is4ms |= anychan(achans, na, IEEE80211_CHAN_4MSXMIT);
1208 if (modes & HAL_MODE_TURBO) {
1209 ahp.ah_currentRD = rd;
1210 if (ath_hal_getchannels(&ahp.h, tchans, IEEE80211_CHAN_MAX, &nt,
1211 HAL_MODE_TURBO, cc, rd, extendedChanMode) == HAL_OK) {
1212 calctxpower(&ahp.h, nt, tchans, tpcReduction, powerLimit, ttxpow);
1214 isdfs |= anychan(tchans, nt, IEEE80211_CHAN_DFS);
1216 is4ms |= anychan(tchans, nt, IEEE80211_CHAN_4MSXMIT);
1219 if (modes & HAL_MODE_108G) {
1220 ahp.ah_currentRD = rd;
1221 if (ath_hal_getchannels(&ahp.h, tgchans, IEEE80211_CHAN_MAX, &ntg,
1222 HAL_MODE_108G, cc, rd, extendedChanMode) == HAL_OK) {
1223 calctxpower(&ahp.h, ntg, tgchans, tpcReduction, powerLimit, tgtxpow);
1225 isdfs |= anychan(tgchans, ntg, IEEE80211_CHAN_DFS);
1227 is4ms |= anychan(tgchans, ntg, IEEE80211_CHAN_4MSXMIT);
1230 if (modes & HAL_MODE_HT) {
1231 ahp.ah_currentRD = rd;
1232 if (ath_hal_getchannels(&ahp.h, nchans, IEEE80211_CHAN_MAX, &nn,
1233 modes & HAL_MODE_HT, cc, rd, extendedChanMode) == HAL_OK) {
1234 calctxpower(&ahp.h, nn, nchans, tpcReduction, powerLimit, ntxpow);
1236 isdfs |= anychan(nchans, nn, IEEE80211_CHAN_DFS);
1238 is4ms |= anychan(nchans, nn, IEEE80211_CHAN_4MSXMIT);
1243 #define CHECKMODES(_modes, _m) ((_modes & (_m)) == (_m))
1244 if (CHECKMODES(modes, HAL_MODE_11B|HAL_MODE_11G)) {
1246 intersect(bchans, btxpow, &nb, gchans, gtxpow, ng);
1248 if (CHECKMODES(modes, HAL_MODE_11A|HAL_MODE_TURBO)) {
1250 intersect(tchans, ttxpow, &nt, achans, atxpow, na);
1252 if (CHECKMODES(modes, HAL_MODE_11G|HAL_MODE_108G)) {
1254 intersect(tgchans, tgtxpow, &ntg, gchans, gtxpow, ng);
1256 if (CHECKMODES(modes, HAL_MODE_11G|HAL_MODE_HT)) {
1258 intersect(gchans, gtxpow, &ng, nchans, ntxpow, nn);
1260 if (CHECKMODES(modes, HAL_MODE_11A|HAL_MODE_HT)) {
1262 intersect(achans, atxpow, &na, nchans, ntxpow, nn);
1267 if (modes & HAL_MODE_11G)
1268 dumpchannels(&ahp.h, ng, gchans, gtxpow);
1269 if (modes & HAL_MODE_11B)
1270 dumpchannels(&ahp.h, nb, bchans, btxpow);
1271 if (modes & HAL_MODE_11A)
1272 dumpchannels(&ahp.h, na, achans, atxpow);
1273 if (modes & HAL_MODE_108G)
1274 dumpchannels(&ahp.h, ntg, tgchans, tgtxpow);
1275 if (modes & HAL_MODE_TURBO)
1276 dumpchannels(&ahp.h, nt, tchans, ttxpow);
1277 if (modes & HAL_MODE_HT)
1278 dumpchannels(&ahp.h, nn, nchans, ntxpow);
1284 * Search a list for a specified value v that is within
1285 * EEP_DELTA of the search values. Return the closest
1286 * values in the list above and below the desired value.
1287 * EEP_DELTA is a factional value; everything is scaled
1288 * so only integer arithmetic is used.
1290 * NB: the input list is assumed to be sorted in ascending order
1293 ar5212GetLowerUpperValues(u_int16_t v, u_int16_t *lp, u_int16_t listSize,
1294 u_int16_t *vlo, u_int16_t *vhi)
1296 u_int32_t target = v * EEP_SCALE;
1297 u_int16_t *ep = lp+listSize;
1300 * Check first and last elements for out-of-bounds conditions.
1302 if (target < (u_int32_t)(lp[0] * EEP_SCALE - EEP_DELTA)) {
1303 *vlo = *vhi = lp[0];
1306 if (target > (u_int32_t)(ep[-1] * EEP_SCALE + EEP_DELTA)) {
1307 *vlo = *vhi = ep[-1];
1311 /* look for value being near or between 2 values in list */
1312 for (; lp < ep; lp++) {
1314 * If value is close to the current value of the list
1315 * then target is not between values, it is one of the values
1317 if (abs(lp[0] * EEP_SCALE - target) < EEP_DELTA) {
1318 *vlo = *vhi = lp[0];
1322 * Look for value being between current value and next value
1323 * if so return these 2 values
1325 if (target < (u_int32_t)(lp[1] * EEP_SCALE - EEP_DELTA)) {
1334 * Find the maximum conformance test limit for the given channel and CTL info
1337 ar5212GetMaxEdgePower(u_int16_t channel, RD_EDGES_POWER *pRdEdgesPower)
1339 /* temp array for holding edge channels */
1340 u_int16_t tempChannelList[NUM_EDGES];
1341 u_int16_t clo, chi, twiceMaxEdgePower;
1344 /* Get the edge power */
1345 for (i = 0; i < NUM_EDGES; i++) {
1346 if (pRdEdgesPower[i].rdEdge == 0)
1348 tempChannelList[i] = pRdEdgesPower[i].rdEdge;
1352 ar5212GetLowerUpperValues(channel, tempChannelList,
1353 numEdges, &clo, &chi);
1354 /* Get the index for the lower channel */
1355 for (i = 0; i < numEdges && clo != tempChannelList[i]; i++)
1357 /* Is lower channel ever outside the rdEdge? */
1358 HALASSERT(i != numEdges);
1360 if ((clo == chi && clo == channel) || (pRdEdgesPower[i].flag)) {
1362 * If there's an exact channel match or an inband flag set
1363 * on the lower channel use the given rdEdgePower
1365 twiceMaxEdgePower = pRdEdgesPower[i].twice_rdEdgePower;
1366 HALASSERT(twiceMaxEdgePower > 0);
1368 twiceMaxEdgePower = MAX_RATE_POWER;
1369 return twiceMaxEdgePower;
1373 * Returns interpolated or the scaled up interpolated value
1376 interpolate(u_int16_t target, u_int16_t srcLeft, u_int16_t srcRight,
1377 u_int16_t targetLeft, u_int16_t targetRight)
1382 /* to get an accurate ratio, always scale, if want to scale, then don't scale back down */
1383 if ((targetLeft * targetRight) == 0)
1386 if (srcRight != srcLeft) {
1388 * Note the ratio always need to be scaled,
1389 * since it will be a fraction.
1391 lRatio = (target - srcLeft) * EEP_SCALE / (srcRight - srcLeft);
1393 /* Return as Left target if value would be negative */
1395 } else if (lRatio > EEP_SCALE) {
1396 /* Return as Right target if Ratio is greater than 100% (SCALE) */
1399 rv = (lRatio * targetRight + (EEP_SCALE - lRatio) *
1400 targetLeft) / EEP_SCALE;
1409 * Return the four rates of target power for the given target power table
1410 * channel, and number of channels
1413 ar5212GetTargetPowers(struct ath_hal *ah, const struct ieee80211_channel *chan,
1414 TRGT_POWER_INFO *powInfo,
1415 u_int16_t numChannels, TRGT_POWER_INFO *pNewPower)
1417 /* temp array for holding target power channels */
1418 u_int16_t tempChannelList[NUM_TEST_FREQUENCIES];
1419 u_int16_t clo, chi, ixlo, ixhi;
1422 /* Copy the target powers into the temp channel list */
1423 for (i = 0; i < numChannels; i++)
1424 tempChannelList[i] = powInfo[i].testChannel;
1426 ar5212GetLowerUpperValues(chan->ic_freq, tempChannelList,
1427 numChannels, &clo, &chi);
1429 /* Get the indices for the channel */
1431 for (i = 0; i < numChannels; i++) {
1432 if (clo == tempChannelList[i]) {
1435 if (chi == tempChannelList[i]) {
1442 * Get the lower and upper channels, target powers,
1443 * and interpolate between them.
1445 pNewPower->twicePwr6_24 = interpolate(chan->ic_freq, clo, chi,
1446 powInfo[ixlo].twicePwr6_24, powInfo[ixhi].twicePwr6_24);
1447 pNewPower->twicePwr36 = interpolate(chan->ic_freq, clo, chi,
1448 powInfo[ixlo].twicePwr36, powInfo[ixhi].twicePwr36);
1449 pNewPower->twicePwr48 = interpolate(chan->ic_freq, clo, chi,
1450 powInfo[ixlo].twicePwr48, powInfo[ixhi].twicePwr48);
1451 pNewPower->twicePwr54 = interpolate(chan->ic_freq, clo, chi,
1452 powInfo[ixlo].twicePwr54, powInfo[ixhi].twicePwr54);
1455 static RD_EDGES_POWER*
1456 findEdgePower(struct ath_hal *ah, u_int ctl)
1460 for (i = 0; i < _numCtls; i++)
1462 return &_rdEdgesPower[i * NUM_EDGES];
1467 * Sets the transmit power in the baseband for the given
1468 * operating channel and mode.
1471 setRateTable(struct ath_hal *ah, const struct ieee80211_channel *chan,
1472 int16_t tpcScaleReduction, int16_t powerLimit,
1473 int16_t *pMinPower, int16_t *pMaxPower)
1475 u_int16_t ratesArray[16];
1476 u_int16_t *rpow = ratesArray;
1477 u_int16_t twiceMaxRDPower, twiceMaxEdgePower, twiceMaxEdgePowerCck;
1478 int8_t twiceAntennaGain, twiceAntennaReduction;
1479 TRGT_POWER_INFO targetPowerOfdm, targetPowerCck;
1480 RD_EDGES_POWER *rep;
1481 int16_t scaledPower;
1484 twiceMaxRDPower = chan->ic_maxregpower * 2;
1485 *pMaxPower = -MAX_RATE_POWER;
1486 *pMinPower = MAX_RATE_POWER;
1488 /* Get conformance test limit maximum for this channel */
1489 cfgCtl = ath_hal_getctl(ah, chan);
1490 rep = findEdgePower(ah, cfgCtl);
1492 twiceMaxEdgePower = ar5212GetMaxEdgePower(chan->ic_freq, rep);
1494 twiceMaxEdgePower = MAX_RATE_POWER;
1496 if (IEEE80211_IS_CHAN_G(chan)) {
1497 /* Check for a CCK CTL for 11G CCK powers */
1498 cfgCtl = (cfgCtl & 0xFC) | 0x01;
1499 rep = findEdgePower(ah, cfgCtl);
1501 twiceMaxEdgePowerCck = ar5212GetMaxEdgePower(chan->ic_freq, rep);
1503 twiceMaxEdgePowerCck = MAX_RATE_POWER;
1505 /* Set the 11B cck edge power to the one found before */
1506 twiceMaxEdgePowerCck = twiceMaxEdgePower;
1509 /* Get Antenna Gain reduction */
1510 if (IEEE80211_IS_CHAN_5GHZ(chan)) {
1511 twiceAntennaGain = antennaGainMax[0];
1513 twiceAntennaGain = antennaGainMax[1];
1515 twiceAntennaReduction =
1516 ath_hal_getantennareduction(ah, chan, twiceAntennaGain);
1518 if (IEEE80211_IS_CHAN_OFDM(chan)) {
1519 /* Get final OFDM target powers */
1520 if (IEEE80211_IS_CHAN_G(chan)) {
1521 /* TODO - add Turbo 2.4 to this mode check */
1522 ar5212GetTargetPowers(ah, chan, trgtPwr_11g,
1523 numTargetPwr_11g, &targetPowerOfdm);
1525 ar5212GetTargetPowers(ah, chan, trgtPwr_11a,
1526 numTargetPwr_11a, &targetPowerOfdm);
1529 /* Get Maximum OFDM power */
1530 /* Minimum of target and edge powers */
1531 scaledPower = AH_MIN(twiceMaxEdgePower,
1532 twiceMaxRDPower - twiceAntennaReduction);
1535 * If turbo is set, reduce power to keep power
1536 * consumption under 2 Watts. Note that we always do
1537 * this unless specially configured. Then we limit
1538 * power only for non-AP operation.
1540 if (IEEE80211_IS_CHAN_TURBO(chan)
1541 #ifdef AH_ENABLE_AP_SUPPORT
1542 && AH_PRIVATE(ah)->ah_opmode != HAL_M_HOSTAP
1546 * If turbo is set, reduce power to keep power
1547 * consumption under 2 Watts
1549 if (eeversion >= AR_EEPROM_VER3_1)
1550 scaledPower = AH_MIN(scaledPower,
1553 * EEPROM version 4.0 added an additional
1554 * constraint on 2.4GHz channels.
1556 if (eeversion >= AR_EEPROM_VER4_0 &&
1557 IEEE80211_IS_CHAN_2GHZ(chan))
1558 scaledPower = AH_MIN(scaledPower,
1561 /* Reduce power by max regulatory domain allowed restrictions */
1562 scaledPower -= (tpcScaleReduction * 2);
1563 scaledPower = (scaledPower < 0) ? 0 : scaledPower;
1564 scaledPower = AH_MIN(scaledPower, powerLimit);
1566 scaledPower = AH_MIN(scaledPower, targetPowerOfdm.twicePwr6_24);
1568 /* Set OFDM rates 9, 12, 18, 24, 36, 48, 54, XR */
1569 rpow[0] = rpow[1] = rpow[2] = rpow[3] = rpow[4] = scaledPower;
1570 rpow[5] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr36);
1571 rpow[6] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr48);
1572 rpow[7] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr54);
1575 if (eeversion >= AR_EEPROM_VER4_0) {
1576 /* Setup XR target power from EEPROM */
1577 rpow[15] = AH_MIN(scaledPower, IS_CHAN_2GHZ(chan) ?
1578 xrTargetPower2 : xrTargetPower5);
1580 /* XR uses 6mb power */
1587 *pMinPower = rpow[7];
1588 *pMaxPower = rpow[0];
1591 ahp->ah_ofdmTxPower = rpow[0];
1594 HALDEBUG(ah, HAL_DEBUG_ANY,
1595 "%s: MaxRD: %d TurboMax: %d MaxCTL: %d "
1596 "TPC_Reduction %d\n", __func__,
1597 twiceMaxRDPower, turbo2WMaxPower5,
1598 twiceMaxEdgePower, tpcScaleReduction * 2);
1601 if (IEEE80211_IS_CHAN_CCK(chan)) {
1602 /* Get final CCK target powers */
1603 ar5212GetTargetPowers(ah, chan, trgtPwr_11b,
1604 numTargetPwr_11b, &targetPowerCck);
1606 /* Reduce power by max regulatory domain allowed restrictions */
1607 scaledPower = AH_MIN(twiceMaxEdgePowerCck,
1608 twiceMaxRDPower - twiceAntennaReduction);
1610 scaledPower -= (tpcScaleReduction * 2);
1611 scaledPower = (scaledPower < 0) ? 0 : scaledPower;
1612 scaledPower = AH_MIN(scaledPower, powerLimit);
1614 rpow[8] = (scaledPower < 1) ? 1 : scaledPower;
1616 /* Set CCK rates 2L, 2S, 5.5L, 5.5S, 11L, 11S */
1617 rpow[8] = AH_MIN(scaledPower, targetPowerCck.twicePwr6_24);
1618 rpow[9] = AH_MIN(scaledPower, targetPowerCck.twicePwr36);
1620 rpow[11] = AH_MIN(scaledPower, targetPowerCck.twicePwr48);
1621 rpow[12] = rpow[11];
1622 rpow[13] = AH_MIN(scaledPower, targetPowerCck.twicePwr54);
1623 rpow[14] = rpow[13];
1625 /* Set min/max power based off OFDM values or initialization */
1626 if (rpow[13] < *pMinPower)
1627 *pMinPower = rpow[13];
1628 if (rpow[9] > *pMaxPower)
1629 *pMaxPower = rpow[9];
1633 ahp->ah_tx6PowerInHalfDbm = *pMaxPower;
1639 ath_hal_malloc(size_t size)
1641 return calloc(1, size);
1645 ath_hal_free(void* p)
1651 ath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap)
1657 ath_hal_printf(struct ath_hal *ah, const char* fmt, ...)
1661 ath_hal_vprintf(ah, fmt, ap);
1666 HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
1668 if (ath_hal_debug & mask) {
1671 ath_hal_vprintf(ah, fmt, ap);