⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 Atheros wifi driver source code
💻 C
📖 第 1 页 / 共 4 页
字号:
#define	CHECKMODES(_modes, _m)	((_modes & (_m)) == (_m))		if (CHECKMODES(modes, HAL_MODE_11B|HAL_MODE_11G)) {			/* b ^= g */			intersect(bchans, btxpow, &nb, gchans, gtxpow, ng);		}		if (CHECKMODES(modes, HAL_MODE_11A|HAL_MODE_TURBO)) {			/* t ^= a */			intersect(tchans, ttxpow, &nt, achans, atxpow, na);		}		if (CHECKMODES(modes, HAL_MODE_11G|HAL_MODE_108G)) {			/* tg ^= g */			intersect(tchans, ttxpow, &ntg, achans, atxpow, ng);		}#undef CHECKMODES	}	if (modes & HAL_MODE_11G)		dumpchannels(&ahp.h, ng, gchans, gtxpow);	if (modes & HAL_MODE_11B)		dumpchannels(&ahp.h, nb, bchans, btxpow);	if (modes & HAL_MODE_11A)		dumpchannels(&ahp.h, na, achans, atxpow);	if (modes & HAL_MODE_108G)		dumpchannels(&ahp.h, ntg, tgchans, tgtxpow);	if (modes & HAL_MODE_TURBO)		dumpchannels(&ahp.h, nt, tchans, ttxpow);	printf("\n");	return (0);}/* * Search a list for a specified value v that is within * EEP_DELTA of the search values.  Return the closest * values in the list above and below the desired value. * EEP_DELTA is a factional value; everything is scaled * so only integer arithmetic is used. * * NB: the input list is assumed to be sorted in ascending order */static voidar5212GetLowerUpperValues(u_int16_t v, u_int16_t *lp, u_int16_t listSize,                          u_int16_t *vlo, u_int16_t *vhi){	u_int32_t target = v * EEP_SCALE;	u_int16_t *ep = lp+listSize;	/*	 * Check first and last elements for out-of-bounds conditions.	 */	if (target < (u_int32_t)(lp[0] * EEP_SCALE - EEP_DELTA)) {		*vlo = *vhi = lp[0];		return;	}	if (target > (u_int32_t)(ep[-1] * EEP_SCALE + EEP_DELTA)) {		*vlo = *vhi = ep[-1];		return;	}	/* look for value being near or between 2 values in list */	for (; lp < ep; lp++) {		/*		 * If value is close to the current value of the list		 * then target is not between values, it is one of the values		 */		if (abs(lp[0] * EEP_SCALE - target) < EEP_DELTA) {			*vlo = *vhi = lp[0];			return;		}		/*		 * Look for value being between current value and next value		 * if so return these 2 values		 */		if (target < (u_int32_t)(lp[1] * EEP_SCALE - EEP_DELTA)) {			*vlo = lp[0];			*vhi = lp[1];			return;		}	}}/* * Find the maximum conformance test limit for the given channel and CTL info */static u_int16_tar5212GetMaxEdgePower(u_int16_t channel, RD_EDGES_POWER *pRdEdgesPower){	/* temp array for holding edge channels */	u_int16_t tempChannelList[NUM_EDGES];	u_int16_t clo, chi, twiceMaxEdgePower;	int i, numEdges;	/* Get the edge power */	for (i = 0; i < NUM_EDGES; i++) {		if (pRdEdgesPower[i].rdEdge == 0)			break;		tempChannelList[i] = pRdEdgesPower[i].rdEdge;	}	numEdges = i;	ar5212GetLowerUpperValues(channel, tempChannelList,		numEdges, &clo, &chi);	/* Get the index for the lower channel */	for (i = 0; i < numEdges && clo != tempChannelList[i]; i++)		;	/* Is lower channel ever outside the rdEdge? */	HALASSERT(i != numEdges);	if ((clo == chi && clo == channel) || (pRdEdgesPower[i].flag)) {		/* 		 * If there's an exact channel match or an inband flag set		 * on the lower channel use the given rdEdgePower 		 */		twiceMaxEdgePower = pRdEdgesPower[i].twice_rdEdgePower;		HALASSERT(twiceMaxEdgePower > 0);	} else		twiceMaxEdgePower = MAX_RATE_POWER;	return twiceMaxEdgePower;}/* * Returns interpolated or the scaled up interpolated value */static u_int16_tinterpolate(u_int16_t target, u_int16_t srcLeft, u_int16_t srcRight,	u_int16_t targetLeft, u_int16_t targetRight){	u_int16_t rv;	int16_t lRatio;	/* to get an accurate ratio, always scale, if want to scale, then don't scale back down */	if ((targetLeft * targetRight) == 0)		return 0;	if (srcRight != srcLeft) {		/*		 * Note the ratio always need to be scaled,		 * since it will be a fraction.		 */		lRatio = (target - srcLeft) * EEP_SCALE / (srcRight - srcLeft);		if (lRatio < 0) {		    /* Return as Left target if value would be negative */		    rv = targetLeft;		} else if (lRatio > EEP_SCALE) {		    /* Return as Right target if Ratio is greater than 100% (SCALE) */		    rv = targetRight;		} else {			rv = (lRatio * targetRight + (EEP_SCALE - lRatio) *					targetLeft) / EEP_SCALE;		}	} else {		rv = targetLeft;	}	return rv;}/* * Return the four rates of target power for the given target power table  * channel, and number of channels */static voidar5212GetTargetPowers(struct ath_hal *ah, HAL_CHANNEL *chan,	TRGT_POWER_INFO *powInfo,	u_int16_t numChannels, TRGT_POWER_INFO *pNewPower){	/* temp array for holding target power channels */	u_int16_t tempChannelList[NUM_TEST_FREQUENCIES];	u_int16_t clo, chi, ixlo, ixhi;	int i;	/* Copy the target powers into the temp channel list */	for (i = 0; i < numChannels; i++)		tempChannelList[i] = powInfo[i].testChannel;	ar5212GetLowerUpperValues(chan->channel, tempChannelList,		numChannels, &clo, &chi);	/* Get the indices for the channel */	ixlo = ixhi = 0;	for (i = 0; i < numChannels; i++) {		if (clo == tempChannelList[i]) {			ixlo = i;		}		if (chi == tempChannelList[i]) {			ixhi = i;			break;		}	}	/*	 * Get the lower and upper channels, target powers,	 * and interpolate between them.	 */	pNewPower->twicePwr6_24 = interpolate(chan->channel, clo, chi,		powInfo[ixlo].twicePwr6_24, powInfo[ixhi].twicePwr6_24);	pNewPower->twicePwr36 = interpolate(chan->channel, clo, chi,		powInfo[ixlo].twicePwr36, powInfo[ixhi].twicePwr36);	pNewPower->twicePwr48 = interpolate(chan->channel, clo, chi,		powInfo[ixlo].twicePwr48, powInfo[ixhi].twicePwr48);	pNewPower->twicePwr54 = interpolate(chan->channel, clo, chi,		powInfo[ixlo].twicePwr54, powInfo[ixhi].twicePwr54);}static RD_EDGES_POWER*findEdgePower(struct ath_hal *ah, u_int ctl){	int i;	for (i = 0; i < _numCtls; i++)		if (_ctl[i] == ctl)			return &_rdEdgesPower[i * NUM_EDGES];	return AH_NULL;}/* * Sets the transmit power in the baseband for the given * operating channel and mode. */static HAL_BOOLsetRateTable(struct ath_hal *ah, HAL_CHANNEL *chan, 		   int16_t tpcScaleReduction, int16_t powerLimit,                   int16_t *pMinPower, int16_t *pMaxPower){	u_int16_t ratesArray[16];	u_int16_t *rpow = ratesArray;	u_int16_t twiceMaxRDPower, twiceMaxEdgePower, twiceMaxEdgePowerCck;	int8_t twiceAntennaGain, twiceAntennaReduction;	TRGT_POWER_INFO targetPowerOfdm, targetPowerCck;	RD_EDGES_POWER *rep;	int16_t scaledPower;	u_int8_t cfgCtl;	twiceMaxRDPower = chan->maxRegTxPower * 2;	*pMaxPower = -MAX_RATE_POWER;	*pMinPower = MAX_RATE_POWER;	/* Get conformance test limit maximum for this channel */	cfgCtl = ath_hal_getctl(ah, chan);	rep = findEdgePower(ah, cfgCtl);	if (rep != AH_NULL)		twiceMaxEdgePower = ar5212GetMaxEdgePower(chan->channel, rep);	else		twiceMaxEdgePower = MAX_RATE_POWER;	if (IS_CHAN_G(chan)) {		/* Check for a CCK CTL for 11G CCK powers */		cfgCtl = (cfgCtl & 0xFC) | 0x01;		rep = findEdgePower(ah, cfgCtl);		if (rep != AH_NULL)			twiceMaxEdgePowerCck = ar5212GetMaxEdgePower(chan->channel, rep);		else			twiceMaxEdgePowerCck = MAX_RATE_POWER;	} else {		/* Set the 11B cck edge power to the one found before */		twiceMaxEdgePowerCck = twiceMaxEdgePower;	}	/* Get Antenna Gain reduction */	if (IS_CHAN_5GHZ(chan)) {		twiceAntennaGain = antennaGainMax[0];	} else {		twiceAntennaGain = antennaGainMax[1];	}	twiceAntennaReduction =		ath_hal_getantennareduction(ah, chan, twiceAntennaGain);	if (IS_CHAN_OFDM(chan)) {		/* Get final OFDM target powers */		if (IS_CHAN_G(chan)) { 			/* TODO - add Turbo 2.4 to this mode check */			ar5212GetTargetPowers(ah, chan, trgtPwr_11g,				numTargetPwr_11g, &targetPowerOfdm);		} else {			ar5212GetTargetPowers(ah, chan, trgtPwr_11a,				numTargetPwr_11a, &targetPowerOfdm);		}		/* Get Maximum OFDM power */		/* Minimum of target and edge powers */		scaledPower = AH_MIN(twiceMaxEdgePower,				twiceMaxRDPower - twiceAntennaReduction);		/*		 * If turbo is set, reduce power to keep power		 * consumption under 2 Watts.  Note that we always do		 * this unless specially configured.  Then we limit		 * power only for non-AP operation.		 */		if (IS_CHAN_TURBO(chan)#ifdef AH_ENABLE_AP_SUPPORT		    && AH_PRIVATE(ah)->ah_opmode != HAL_M_HOSTAP#endif		) {			/*			 * If turbo is set, reduce power to keep power			 * consumption under 2 Watts			 */			if (eeversion >= AR_EEPROM_VER3_1)				scaledPower = AH_MIN(scaledPower,					turbo2WMaxPower5);			/*			 * EEPROM version 4.0 added an additional			 * constraint on 2.4GHz channels.			 */			if (eeversion >= AR_EEPROM_VER4_0 &&			    IS_CHAN_2GHZ(chan))				scaledPower = AH_MIN(scaledPower,					turbo2WMaxPower2);		}		/* Reduce power by max regulatory domain allowed restrictions */		scaledPower -= (tpcScaleReduction * 2);		scaledPower = (scaledPower < 0) ? 0 : scaledPower;		scaledPower = AH_MIN(scaledPower, powerLimit);		scaledPower = AH_MIN(scaledPower, targetPowerOfdm.twicePwr6_24);		/* Set OFDM rates 9, 12, 18, 24, 36, 48, 54, XR */		rpow[0] = rpow[1] = rpow[2] = rpow[3] = rpow[4] = scaledPower;		rpow[5] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr36);		rpow[6] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr48);		rpow[7] = AH_MIN(rpow[0], targetPowerOfdm.twicePwr54);#ifdef notyet		if (eeversion >= AR_EEPROM_VER4_0) {			/* Setup XR target power from EEPROM */			rpow[15] = AH_MIN(scaledPower, IS_CHAN_2GHZ(chan) ?				xrTargetPower2 : xrTargetPower5);		} else {			/* XR uses 6mb power */			rpow[15] = rpow[0];		}#else		rpow[15] = rpow[0];#endif		*pMinPower = rpow[7];		*pMaxPower = rpow[0];#if 0		ahp->ah_ofdmTxPower = rpow[0];#endif		HALDEBUG(ah, "%s: MaxRD: %d TurboMax: %d MaxCTL: %d "			"TPC_Reduction %d\n",			__func__,			twiceMaxRDPower, turbo2WMaxPower5,			twiceMaxEdgePower, tpcScaleReduction * 2);	}	if (IS_CHAN_CCK(chan) || IS_CHAN_G(chan)) {		/* Get final CCK target powers */		ar5212GetTargetPowers(ah, chan, trgtPwr_11b,			numTargetPwr_11b, &targetPowerCck);		/* Reduce power by max regulatory domain allowed restrictions */		scaledPower = AH_MIN(twiceMaxEdgePowerCck,			twiceMaxRDPower - twiceAntennaReduction);		scaledPower -= (tpcScaleReduction * 2);		scaledPower = (scaledPower < 0) ? 0 : scaledPower;		scaledPower = AH_MIN(scaledPower, powerLimit);		rpow[8] = (scaledPower < 1) ? 1 : scaledPower;		/* Set CCK rates 2L, 2S, 5.5L, 5.5S, 11L, 11S */		rpow[8]  = AH_MIN(scaledPower, targetPowerCck.twicePwr6_24);		rpow[9]  = AH_MIN(scaledPower, targetPowerCck.twicePwr36);		rpow[10] = rpow[9];		rpow[11] = AH_MIN(scaledPower, targetPowerCck.twicePwr48);		rpow[12] = rpow[11];		rpow[13] = AH_MIN(scaledPower, targetPowerCck.twicePwr54);		rpow[14] = rpow[13];		/* Set min/max power based off OFDM values or initialization */		if (rpow[13] < *pMinPower)		    *pMinPower = rpow[13];		if (rpow[9] > *pMaxPower)		    *pMaxPower = rpow[9];	}#if 0	ahp->ah_tx6PowerInHalfDbm = *pMaxPower;#endif	return AH_TRUE;}void*ath_hal_malloc(size_t size){	return calloc(1, size);}voidath_hal_free(void* p){	return free(p);}voidath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap){	vprintf(fmt, ap);}voidath_hal_printf(struct ath_hal *ah, const char* fmt, ...){	va_list ap;	va_start(ap, fmt);	ath_hal_vprintf(ah, fmt, ap);	va_end(ap);}voidHALDEBUG(struct ath_hal *ah, const char* fmt, ...){	if (ath_hal_debug) {		__va_list ap;		va_start(ap, fmt);		ath_hal_vprintf(ah, fmt, ap);		va_end(ap);	}}voidHALDEBUGn(struct ath_hal *ah, u_int level, const char* fmt, ...){	if (ath_hal_debug >= level) {		__va_list ap;		va_start(ap, fmt);		ath_hal_vprintf(ah, fmt, ap);		va_end(ap);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -