📄 main.c
字号:
{CTRY_KOREA_NORTH, APL2_WORLD, "KP", "NORTH KOREA",YES,YES, YES }, {CTRY_KOREA_ROC, APL2_WORLD, "KR", "KOREA REPUBLIC", YES, NO, NO }, {CTRY_KOREA_ROC2, APL2_APLD, "K2", "KOREA REPUBLIC2", YES, NO, NO }, {CTRY_KUWAIT, NULL1_WORLD, "KW", "KUWAIT", YES, NO, YES }, {CTRY_LATVIA, ETSI1_WORLD, "LV", "LATVIA", YES, NO, YES }, {CTRY_LEBANON, NULL1_WORLD, "LB", "LEBANON", YES, NO, YES }, {CTRY_LIECHTENSTEIN,ETSI4_WORLD, "LI", "LIECHTENSTEIN", YES, NO, YES }, {CTRY_LITHUANIA, ETSI1_WORLD, "LT", "LITHUANIA", YES, NO, YES }, {CTRY_LUXEMBOURG, ETSI1_WORLD, "LU", "LUXEMBOURG", YES, NO, YES }, {CTRY_MACAU, FCC2_WORLD, "MO", "MACAU", YES, YES, YES }, {CTRY_MACEDONIA, NULL1_WORLD, "MK", "MACEDONIA", YES, NO, YES }, {CTRY_MALAYSIA, NULL1_WORLD, "MY", "MALAYSIA", NO, NO, NO }, {CTRY_MEXICO, FCC1_FCCA, "MX", "MEXICO", YES, YES, YES }, {CTRY_MONACO, ETSI4_WORLD, "MC", "MONACO", YES, YES, YES }, {CTRY_MOROCCO, NULL1_WORLD, "MA", "MOROCCO", YES, NO, YES }, {CTRY_NETHERLANDS, ETSI1_WORLD, "NL", "NETHERLANDS",YES, NO, YES }, {CTRY_NEW_ZEALAND, FCC2_ETSIC, "NZ", "NEW ZEALAND",YES, NO, YES }, {CTRY_NORWAY, ETSI1_WORLD, "NO", "NORWAY", YES, NO, YES }, {CTRY_OMAN, ETSI3_WORLD, "OM", "OMAN", YES, NO, YES }, {CTRY_PAKISTAN, NULL1_WORLD, "PK", "PAKISTAN", YES, NO, YES }, {CTRY_PANAMA, FCC1_FCCA, "PA", "PANAMA", YES, YES, YES }, {CTRY_PERU, APL1_WORLD, "PE", "PERU", YES, NO, YES }, {CTRY_PHILIPPINES, APL1_WORLD, "PH", "PHILIPPINES",YES, YES, YES }, {CTRY_POLAND, ETSI1_WORLD, "PL", "POLAND", YES, NO, YES }, {CTRY_PORTUGAL, ETSI1_WORLD, "PT", "PORTUGAL", YES, NO, YES }, {CTRY_PUERTO_RICO, FCC1_FCCA, "PR", "PUERTO RICO",YES, YES, YES }, {CTRY_QATAR, NULL1_WORLD, "QA", "QATAR", YES, NO, YES }, {CTRY_ROMANIA, NULL1_WORLD, "RO", "ROMANIA", YES, NO, YES }, {CTRY_RUSSIA, NULL1_WORLD, "RU", "RUSSIA", YES, NO, YES }, {CTRY_SAUDI_ARABIA,NULL1_WORLD, "SA", "SAUDI ARABIA", YES, NO, YES }, {CTRY_SINGAPORE, APL6_WORLD, "SG", "SINGAPORE", YES, YES, YES }, {CTRY_SLOVAKIA, ETSI3_WORLD, "SK", "SLOVAK REPUBLIC", YES, NO, YES }, {CTRY_SLOVENIA, ETSI1_WORLD, "SI", "SLOVENIA", YES, NO, YES }, {CTRY_SOUTH_AFRICA,ETSI1_WORLD, "ZA", "SOUTH AFRICA", YES, YES, YES }, {CTRY_SPAIN, ETSI1_WORLD, "ES", "SPAIN", YES, NO, YES }, {CTRY_SWEDEN, ETSI1_WORLD, "SE", "SWEDEN", YES, NO, YES }, {CTRY_SWITZERLAND, ETSI4_WORLD, "CH", "SWITZERLAND",YES, NO, YES }, {CTRY_SYRIA, NULL1_WORLD, "SY", "SYRIA", YES, NO, YES }, {CTRY_TAIWAN, APL3_WORLD, "TW", "TAIWAN", YES, YES, YES }, {CTRY_THAILAND, APL2_WORLD, "TH", "THAILAND", YES, YES, YES }, {CTRY_TRINIDAD_Y_TOBAGO,ETSI4_WORLD,"TT", "TRINIDAD & TOBAGO", YES, NO, YES }, {CTRY_TUNISIA, ETSI3_WORLD, "TN", "TUNISIA", YES, NO, YES }, {CTRY_TURKEY, ETSI3_WORLD, "TR", "TURKEY", YES, NO, YES }, {CTRY_UKRAINE, NULL1_WORLD, "UA", "UKRAINE", YES, NO, YES }, {CTRY_UAE, NULL1_WORLD, "AE", "UNITED ARAB EMIRATES", YES, NO, YES }, {CTRY_UNITED_KINGDOM, ETSI1_WORLD, "GB", "UNITED KINGDOM", YES, NO, YES }, {CTRY_UNITED_STATES, FCC1_FCCA, "US", "UNITED STATES", YES, YES, YES }, {CTRY_UNITED_STATES_FCC49, FCC4_FCCA, "PS", "UNITED STATES (PUBLIC SAFETY)", YES, YES, YES}, {CTRY_URUGUAY, APL2_WORLD, "UY", "URUGUAY", YES, NO, YES }, {CTRY_UZBEKISTAN, FCC3_FCCA, "UZ", "UZBEKISTAN", YES, YES, YES }, {CTRY_VENEZUELA, APL2_ETSIC, "VE", "VENEZUELA", YES, NO, YES }, {CTRY_VIET_NAM, NULL1_WORLD, "VN", "VIET NAM", YES, NO, YES }, {CTRY_YEMEN, NULL1_WORLD, "YE", "YEMEN", YES, NO, YES }, {CTRY_ZIMBABWE, NULL1_WORLD, "ZW", "ZIMBABWE", YES, NO, YES } };#undef YES#undef NOstatic HAL_BOOLcclookup(const char *name, HAL_REG_DOMAIN *rd, HAL_CTRY_CODE *cc){#define N(a) (sizeof(a)/sizeof(a[0])) int i; for (i = 0; i < N(allCountries); i++) if (strcasecmp(allCountries[i].isoName, name) == 0 || strcasecmp(allCountries[i].name, name) == 0) { *rd = allCountries[i].regDmnEnum; *cc = allCountries[i].countryCode; return AH_TRUE; } return AH_FALSE;#undef N}static const char *getccname(HAL_CTRY_CODE cc){#define N(a) (sizeof(a)/sizeof(a[0])) int i; for (i = 0; i < N(allCountries); i++) if (allCountries[i].countryCode == cc) return allCountries[i].name; return NULL;#undef N}static const char *getccisoname(HAL_CTRY_CODE cc){#define N(a) (sizeof(a)/sizeof(a[0])) int i; for (i = 0; i < N(allCountries); i++) if (allCountries[i].countryCode == cc) return allCountries[i].isoName; return NULL;#undef N}static voidcclist(){#define N(a) (sizeof(a)/sizeof(a[0])) int i; printf("\nCountry codes:\n"); for (i = 0; i < N(allCountries); i++) printf("%2s %-15.15s%s", allCountries[i].isoName, allCountries[i].name, ((i+1)%4) == 0 ? "\n" : " "); printf("\n");#undef N}static HAL_BOOLsetRateTable(struct ath_hal *ah, HAL_CHANNEL *chan, int16_t tpcScaleReduction, int16_t powerLimit, int16_t *pMinPower, int16_t *pMaxPower);static voidcalctxpower(struct ath_hal *ah, int nchan, HAL_CHANNEL *chans, int16_t tpcScaleReduction, int16_t powerLimit, int16_t *txpow){ int16_t minpow; int i; for (i = 0; i < nchan; i++) if (!setRateTable(ah, &chans[i], tpcScaleReduction, powerLimit, &minpow, &txpow[i])) { printf("unable to set rate table\n"); exit(-1); }}int n = 1;const char *sep = "";int dopassive = 0;int showchannels = 0;static voiddumpchannels(struct ath_hal *ah, int nc, HAL_CHANNEL *chans, int16_t *txpow){ int i; for (i = 0; i < nc; i++) { HAL_CHANNEL *c = &chans[i]; int type; if (showchannels) printf("%s%3u", sep, ath_hal_mhz2ieee(ah, c->channel, c->channelFlags)); else printf("%s%u", sep, c->channel); if (IS_CHAN_TURBO(c)) type = 'T'; else if (IS_CHAN_A(c)) type = 'A'; else if (IS_CHAN_108G(c)) type = 'T'; else if (IS_CHAN_G(c)) type = 'G'; else type = 'B'; if (dopassive && IS_CHAN_PASSIVE(c)) type = tolower(type); printf("%c %d.%d", type, txpow[i]/2, (txpow[i]%2)*5); if ((n++ % (showchannels ? 7 : 6)) == 0) sep = "\n"; else sep = " "; }}static voidcheckchannels(struct ath_hal *ah, HAL_CHANNEL *chans, int nchan){ int i; for (i = 0; i < nchan; i++) { HAL_CHANNEL *c = &chans[i]; if (!ath_hal_checkchannel(ah, c)) printf("Channel %u (0x%x) disallowed\n", c->channel, c->channelFlags); }}static voidintersect(HAL_CHANNEL *dst, int16_t *dtxpow, int *nd, const HAL_CHANNEL *src, int16_t *stxpow, int ns){ int i = 0, j, k, l; while (i < *nd) { for (j = 0; j < ns && dst[i].channel != src[j].channel; j++) ; if (j < ns && dtxpow[i] == stxpow[j]) { for (k = i+1, l = i; k < *nd; k++, l++) dst[l] = dst[k]; (*nd)--; } else i++; }}static voidusage(const char *progname){ printf("usage: %s [-o] [-i] [cc | rd]\n", progname); exit(-1);}u_intath_hal_mhz2ieee(struct ath_hal *ah, u_int freq, u_int flags){ if (flags & CHANNEL_2GHZ) { /* 2GHz band */ if (freq == 2484) return 14; if (freq < 2484) return (freq - 2407) / 5; else return 15 + ((freq - 2512) / 20); } else if (flags & CHANNEL_5GHZ) {/* 5Ghz band */ if (ath_hal_ispublicsafetysku(ah) && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) { return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400) / 5; } else if ((flags & CHANNEL_A) && (freq <= 5000)) { return (freq - 4000) / 5; } else { return (freq - 5000) / 5; } } else { /* either, guess */ if (freq == 2484) return 14; if (freq < 2484) return (freq - 2407) / 5; if (freq < 5000) { if (ath_hal_ispublicsafetysku(ah) && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) { return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400)/5; } else if (freq > 4900) { return (freq - 4000) / 5; } else { return 15 + ((freq - 2512) / 20); } } return (freq - 5000) / 5; }}static HAL_BOOLgetChipPowerLimits(struct ath_hal *ah, HAL_CHANNEL *chans, u_int32_t nchan){} intmain(int argc, char *argv[]){ static const u_int16_t tpcScaleReductionTable[5] = { 0, 3, 6, 9, MAX_RATE_POWER }; struct ath_hal_private ahp; HAL_CHANNEL achans[IEEE80211_CHAN_MAX]; int16_t atxpow[IEEE80211_CHAN_MAX]; HAL_CHANNEL bchans[IEEE80211_CHAN_MAX]; int16_t btxpow[IEEE80211_CHAN_MAX]; HAL_CHANNEL gchans[IEEE80211_CHAN_MAX]; int16_t gtxpow[IEEE80211_CHAN_MAX]; HAL_CHANNEL tchans[IEEE80211_CHAN_MAX]; int16_t ttxpow[IEEE80211_CHAN_MAX]; HAL_CHANNEL tgchans[IEEE80211_CHAN_MAX]; int16_t tgtxpow[IEEE80211_CHAN_MAX]; int i, na, nb, ng, nt, ntg; HAL_BOOL showall = AH_FALSE; HAL_BOOL extendedChanMode = AH_TRUE; int modes = 0; int16_t tpcReduction, powerLimit; int8_t regids[IEEE80211_REGCLASSIDS_MAX]; int nregids; memset(&ahp, 0, sizeof(ahp)); ahp.ah_getChannelEdges = getChannelEdges; ahp.ah_getWirelessModes = getWirelessModes; ahp.ah_getChipPowerLimits = getChipPowerLimits; ahp.h.ah_getCapability = getCapability; ahp.ah_opmode = HAL_M_STA; ahp.ah_currentRD = 169; /* FCC */ tpcReduction = tpcScaleReductionTable[0]; powerLimit = MAX_RATE_POWER; while ((i = getopt(argc, argv, "acdefoilm:pABGT")) != -1) switch (i) { case 'a': showall = AH_TRUE; break; case 'c': showchannels = AH_TRUE; break; case 'd': ath_hal_debug = 1; break; case 'e': extendedChanMode = AH_FALSE; break; case 'f': showchannels = AH_FALSE; break; case 'o': outdoor = AH_TRUE; break; case 'i': outdoor = AH_FALSE; break; case 'l': cclist(); rdlist(); exit(0); case 'm': if (strncasecmp(optarg, "sta", 2) == 0) ahp.ah_opmode = HAL_M_STA; else if (strncasecmp(optarg, "ibss", 2) == 0) ahp.ah_opmode = HAL_M_IBSS; else if (strncasecmp(optarg, "adhoc", 2) == 0) ahp.ah_opmode = HAL_M_IBSS; else if (strncasecmp(optarg, "ap", 2) == 0) ahp.ah_opmode = HAL_M_HOSTAP; else if (strncasecmp(optarg, "hostap", 2) == 0) ahp.ah_opmode = HAL_M_HOSTAP; else if (strncasecmp(optarg, "monitor", 2) == 0) ahp.ah_opmode = HAL_M_MONITOR; else usage(argv[0]); break; case 'p': dopassive = 1; break; case 'A': modes |= HAL_MODE_11A; break; case 'B': modes |= HAL_MODE_11B; break; case 'G': modes |= HAL_MODE_11G; break; case 'T': modes |= HAL_MODE_TURBO | HAL_MODE_108G; break; default: usage(argv[0]); } if (optind < argc) { if (!cclookup(argv[optind], &ahp.ah_currentRD, &cc)) { if (!rdlookup(argv[optind], &ahp.ah_currentRD)) { const char* rdname; ahp.ah_currentRD = strtoul(argv[optind], NULL, 0); rdname = getrdname(ahp.ah_currentRD); if (rdname == NULL) { printf("%s: unknown country/regulatory " "domain code\n", argv[optind]); exit(-1); } } if (optind+1 < argc) cc = strtoul(argv[optind+1], NULL, 0); else cc = CTRY_DEFAULT; } } else { if (!cclookup("US", &ahp.ah_currentRD, &cc)) { printf("%s: unknown country code\n", "US"); exit(-1); } } if (cc != CTRY_DEFAULT) printf("\n%s (%s, 0x%x, %u) %s (0x%x, %u)\n", getccname(cc), getccisoname(cc), cc, cc, getrdname(ahp.ah_currentRD), ahp.ah_currentRD, ahp.ah_currentRD); else printf("\n%s (0x%x, %u)\n", getrdname(ahp.ah_currentRD), ahp.ah_currentRD, ahp.ah_currentRD); if (modes == 0) modes = HAL_MODE_11A | HAL_MODE_11B | HAL_MODE_11G | HAL_MODE_TURBO | HAL_MODE_108G; if (modes & HAL_MODE_11G) { if (ath_hal_init_channels(&ahp.h, gchans, IEEE80211_CHAN_MAX, &ng, regids, IEEE80211_REGCLASSIDS_MAX, &nregids, cc, HAL_MODE_11G, outdoor, extendedChanMode)) { checkchannels(&ahp.h, gchans, ng); calctxpower(&ahp.h, ng, gchans, tpcReduction, powerLimit, gtxpow); } } if (modes & HAL_MODE_11B) { if (ath_hal_init_channels(&ahp.h, bchans, IEEE80211_CHAN_MAX, &nb, regids, IEEE80211_REGCLASSIDS_MAX, &nregids, cc, HAL_MODE_11B, outdoor, extendedChanMode)) { checkchannels(&ahp.h, bchans, nb); calctxpower(&ahp.h, nb, bchans, tpcReduction, powerLimit, btxpow); } } if (modes & HAL_MODE_11A) { if (ath_hal_init_channels(&ahp.h, achans, IEEE80211_CHAN_MAX, &na, regids, IEEE80211_REGCLASSIDS_MAX, &nregids, cc, HAL_MODE_11A, outdoor, extendedChanMode)) { checkchannels(&ahp.h, achans, na); calctxpower(&ahp.h, na, achans, tpcReduction, powerLimit, atxpow); } } if (modes & HAL_MODE_TURBO) { if (ath_hal_init_channels(&ahp.h, tchans, IEEE80211_CHAN_MAX, &nt, regids, IEEE80211_REGCLASSIDS_MAX, &nregids, cc, HAL_MODE_TURBO, outdoor, extendedChanMode)) { checkchannels(&ahp.h, tchans, nt); calctxpower(&ahp.h, nt, tchans, tpcReduction, powerLimit, ttxpow); } } if (modes & HAL_MODE_108G) { if (ath_hal_init_channels(&ahp.h, tgchans, IEEE80211_CHAN_MAX, &ntg, regids, IEEE80211_REGCLASSIDS_MAX, &nregids, cc, HAL_MODE_108G, outdoor, extendedChanMode)) { checkchannels(&ahp.h, tgchans, ntg); calctxpower(&ahp.h, ntg, tgchans, tpcReduction, powerLimit, tgtxpow); } } if (!showall) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -