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

📄 sample.c

📁 最新之atheros芯片driver source code, 基于linux操作系统,內含atheros芯片HAL全部代码
💻 C
📖 第 1 页 / 共 3 页
字号:
				long_tries > tries[0]);			long_tries -= tries[0];		}		if (tries[1] && ndx[1] >= 0 && finalTSIdx > 0) {			update_stats(sc, an, frame_size,				ndx[1], tries[1],				ndx[2], tries[2],				ndx[3], tries[3],				0, 0,				short_tries, long_tries,				ts->ts_status);			long_tries -= tries[1];		}		if (tries[2] && ndx[2] >= 0 && finalTSIdx > 1) {			update_stats(sc, an, frame_size,				ndx[2], tries[2],				ndx[3], tries[3],				0, 0,				0, 0,				short_tries, long_tries,				ts->ts_status);			long_tries -= tries[2];		}		if (tries[3] && ndx[3] >= 0 && finalTSIdx > 2) {			update_stats(sc, an, frame_size,				ndx[3], tries[3],				0, 0,				0, 0,				0, 0,				short_tries, long_tries,				ts->ts_status);		}	}}static voidath_rate_newassoc(struct ath_softc *sc, struct ath_node *an, int isnew){	DPRINTF(sc, ATH_DEBUG_RATE, "%s: " MAC_FMT " %s isnew %d\n", dev_info,		MAC_ADDR(an->an_node.ni_macaddr), __func__, isnew);	if (isnew)		ath_rate_ctl_reset(sc, &an->an_node);}/* * Initialize the tables for a node. */static voidath_rate_ctl_reset(struct ath_softc *sc, struct ieee80211_node *ni){	struct ath_node *an = ATH_NODE(ni);	struct sample_node *sn = ATH_NODE_SAMPLE(an);	struct ieee80211vap *vap = ni->ni_vap;	const HAL_RATE_TABLE *rt = sc->sc_currates;	unsigned int x, y;	unsigned int srate;	sn->num_rates = 0;	if (rt == NULL) {		printk(KERN_WARNING "no rates yet! mode %u\n", sc->sc_curmode);		return;	}	sn->static_rate_ndx = -1;	sn->num_rates = ni->ni_rates.rs_nrates;	for (x = 0; x < ni->ni_rates.rs_nrates; x++) {		sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL;		sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate];		if (sn->rates[x].rix == 0xff) {			DPRINTF(sc, ATH_DEBUG_RATE, "%s: %s ignore bogus rix at %u\n",				dev_info, __func__, x);			continue;		}		sn->rates[x].rateCode = rt->info[sn->rates[x].rix].rateCode;		sn->rates[x].shortPreambleRateCode =			rt->info[sn->rates[x].rix].rateCode |			rt->info[sn->rates[x].rix].shortPreamble;	}	ni->ni_txrate = 0;	sn->num_rates = ni->ni_rates.rs_nrates;	if (sn->num_rates <= 0) {		DPRINTF(sc, ATH_DEBUG_RATE,"%s: %s " MAC_FMT " no rates (fixed %u) \n",			dev_info, __func__, MAC_ADDR(ni->ni_macaddr),			vap->iv_fixed_rate);		/* there are no rates yet we're done */		return;	}	if (vap->iv_fixed_rate != IEEE80211_FIXED_RATE_NONE) {		/*		 * A fixed rate is to be used; ic_fixed_rate is an		 * index into the supported rate set.  Convert this		 * to the index into the negotiated rate set for		 * the node.  We know the rate is there because the		 * rate set is checked when the station associates.		 */		/* NB: the rate set is assumed sorted */		for (x = 0, srate = 0; x < sn->num_rates; x++)			if ((ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL) == vap->iv_fixed_rate)				srate = x;		KASSERT(((ni->ni_rates.rs_rates[srate] & IEEE80211_RATE_VAL) == vap->iv_fixed_rate),			("fixed rate %u not in rate set", vap->iv_fixed_rate));		sn->static_rate_ndx = srate;		ni->ni_txrate = srate;		DPRINTF(sc, ATH_DEBUG_RATE, "%s: %s " MAC_FMT " fixed rate %u%sMbps\n",			dev_info, __func__, MAC_ADDR(ni->ni_macaddr),			sn->rates[srate].rate / 2,			(sn->rates[srate].rate % 0x1) ? ".5" : " ");		return;	}	for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {		unsigned int size = bin_to_size(y);		int ndx = 0;		sn->packets_sent[y] = 0;		sn->current_sample_ndx[y] = -1;		sn->last_sample_ndx[y] = 0;		for (x = 0; x < ni->ni_rates.rs_nrates; x++) {			if (sn->rates[x].rix == 0xff) {				DPRINTF(sc, ATH_DEBUG_RATE, "%s: %s ignore bogus rix at %u\n",					dev_info, __func__, x);				continue;			}			sn->stats[y][x].successive_failures = 0;			sn->stats[y][x].tries = 0;			sn->stats[y][x].total_packets = 0;			sn->stats[y][x].packets_acked = 0;			sn->stats[y][x].last_tx = 0;			sn->stats[y][x].perfect_tx_time =				calc_usecs_unicast_packet(sc, size,					sn->rates[x].rix,					0, 0);			sn->stats[y][x].average_tx_time =				sn->stats[y][x].perfect_tx_time;		}		/* set the initial rate */		for (ndx = sn->num_rates - 1; ndx > 0; ndx--)			if (sn->rates[ndx].rate <= 72)				break;		sn->current_rate[y] = ndx;	}	DPRINTF(sc, ATH_DEBUG_RATE, "%s: %s " MAC_FMT 		" %u rates %u%sMbps (%uus)- %u%sMbps (%uus)\n",		dev_info, __func__, MAC_ADDR(ni->ni_macaddr),		sn->num_rates,		sn->rates[0].rate / 2, sn->rates[0].rate % 0x1 ? ".5" : "",		sn->stats[1][0].perfect_tx_time,		sn->rates[sn->num_rates-1].rate / 2,		sn->rates[sn->num_rates-1].rate % 0x1 ? ".5" : "",		sn->stats[1][sn->num_rates-1].perfect_tx_time);	ni->ni_txrate = sn->current_rate[0];}static voidath_rate_cb(void *arg, struct ieee80211_node *ni){	ath_rate_ctl_reset(netdev_priv(ni->ni_ic->ic_dev), ni);}/* * Reset the rate control state for each 802.11 state transition. */static voidath_rate_newstate(struct ieee80211vap *vap, enum ieee80211_state newstate){	struct ieee80211com *ic = vap->iv_ic;	if (newstate == IEEE80211_S_RUN) {		if (ic->ic_opmode != IEEE80211_M_STA) {			/*			 * Sync rates for associated stations and neighbors.			 */			ieee80211_iterate_nodes(&ic->ic_sta, ath_rate_cb, NULL);		}		ath_rate_newassoc(netdev_priv(ic->ic_dev), ATH_NODE(vap->iv_bss), 1);	}}static struct ath_ratectrl *ath_rate_attach(struct ath_softc *sc){	struct sample_softc *osc;	DPRINTF(sc, ATH_DEBUG_ANY, "%s: %s\n", dev_info, __func__);	_MOD_INC_USE(THIS_MODULE, return NULL);	osc = kmalloc(sizeof(struct sample_softc), GFP_ATOMIC);	if (osc == NULL) {		_MOD_DEC_USE(THIS_MODULE);		return NULL;	}	osc->arc.arc_space = sizeof(struct sample_node);	osc->arc.arc_vap_space = 0;	osc->ath_smoothing_rate = ath_smoothing_rate;	osc->ath_sample_rate = ath_sample_rate;	return &osc->arc;}static voidath_rate_detach(struct ath_ratectrl *arc){	struct sample_softc *osc = (struct sample_softc *)arc;	kfree(osc);	_MOD_DEC_USE(THIS_MODULE);}static intproc_read_nodes(struct ieee80211vap *vap, const int size, char *buf, int space){	char *p = buf;	struct ieee80211_node *ni;	struct ath_node *an;	struct sample_node *sn;	struct ieee80211_node_table *nt =		(struct ieee80211_node_table *)&vap->iv_ic->ic_sta;	unsigned int ndx;	unsigned int size_bin;	IEEE80211_NODE_TABLE_LOCK_IRQ(nt);	TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {		/* Assume each node needs 500 bytes */		if (buf + space < p + 500)			break;		an = ATH_NODE(ni);		sn = ATH_NODE_SAMPLE(an);		/* Skip ourself */		if (memcmp(vap->iv_myaddr, ni->ni_macaddr,					IEEE80211_ADDR_LEN)==0) {			continue;		}		size_bin = size_to_bin(size);		p += sprintf(p, MAC_FMT "\n", MAC_ADDR(ni->ni_macaddr));		p += sprintf(p,				"rate\ttt\tperfect\tfailed\tpkts\tavg_tries\tlast_tx\n");		for (ndx = 0; ndx < sn->num_rates; ndx++) {			unsigned int a = 1;			unsigned int t = 1;			p += sprintf(p, "%s", 					(ndx == sn->current_rate[size_bin]) ? "*" : " ");			p += sprintf(p, "%3u%s",					sn->rates[ndx].rate / 2,					(sn->rates[ndx].rate & 0x1) ? ".5" : ".0");			p += sprintf(p, "\t%4u\t%4u\t%2u\t%6u",					sn->stats[size_bin][ndx].average_tx_time,					sn->stats[size_bin][ndx].perfect_tx_time,					sn->stats[size_bin][ndx].successive_failures,					sn->stats[size_bin][ndx].total_packets);			if (sn->stats[size_bin][ndx].total_packets) {				a = sn->stats[size_bin][ndx].total_packets;				t = sn->stats[size_bin][ndx].tries;  			}			p += sprintf(p, "\t%u.%02u\t\t", t / a, (t * 100 / a) % 100);			if (sn->stats[size_bin][ndx].last_tx) {  				unsigned long d = jiffies - 					sn->stats[size_bin][ndx].last_tx;				p += sprintf(p, "%lu.%02lu", d / HZ, d % HZ);			} else {				p += sprintf(p, "-");			}			p += sprintf(p, "\n");		}	}	IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);	return (p - buf);}static intproc_ratesample_open(struct inode *inode, struct file *file){	struct proc_ieee80211_priv *pv;	struct proc_dir_entry *dp = PDE(inode);	struct ieee80211vap *vap = dp->data;	unsigned long size;	if (!(file->private_data = kzalloc(sizeof(struct proc_ieee80211_priv),			GFP_KERNEL)))		return -ENOMEM;	/* initially allocate both read and write buffers */	pv = (struct proc_ieee80211_priv *)file->private_data;	pv->rbuf = vmalloc(MAX_PROC_IEEE80211_SIZE);	if (!pv->rbuf) {		kfree(pv);		return -ENOMEM;	}	pv->wbuf = vmalloc(MAX_PROC_IEEE80211_SIZE);	if (!pv->wbuf) {		vfree(pv->rbuf);		kfree(pv);		return -ENOMEM;	}	memset(pv->wbuf, 0, MAX_PROC_IEEE80211_SIZE);	memset(pv->rbuf, 0, MAX_PROC_IEEE80211_SIZE);	pv->max_wlen = MAX_PROC_IEEE80211_SIZE;	pv->max_rlen = MAX_PROC_IEEE80211_SIZE;	/* Determine what size packets to get stats for based on proc filename */	size = simple_strtoul(dp->name + 10, NULL, 0);	/* now read the data into the buffer */	pv->rlen = proc_read_nodes(vap, size, pv->rbuf, MAX_PROC_IEEE80211_SIZE);	return 0;}static struct file_operations proc_ratesample_ops = {	.read = NULL,	.write = NULL,	.open = proc_ratesample_open,	.release = NULL,};static voidath_rate_dynamic_proc_register(struct ieee80211vap *vap){	/* Create proc entries for the rate control algorithm */	ieee80211_proc_vcreate(vap, &proc_ratesample_ops, "ratestats_250");	ieee80211_proc_vcreate(vap, &proc_ratesample_ops, "ratestats_1600");	ieee80211_proc_vcreate(vap, &proc_ratesample_ops, "ratestats_3000");}static struct ieee80211_rate_ops ath_rate_ops = {	.ratectl_id = IEEE80211_RATE_SAMPLE,	.node_init = ath_rate_node_init,	.node_cleanup = ath_rate_node_cleanup,	.findrate = ath_rate_findrate,	.get_mrr = ath_rate_get_mrr,	.tx_complete = ath_rate_tx_complete,	.newassoc = ath_rate_newassoc,	.newstate = ath_rate_newstate,	.attach = ath_rate_attach,	.detach = ath_rate_detach,	.dynamic_proc_register = ath_rate_dynamic_proc_register,};MODULE_AUTHOR("John Bicket");MODULE_DESCRIPTION("SampleRate bit-rate selection algorithm for Atheros devices");#ifdef MODULE_VERSIONMODULE_VERSION(RELEASE_VERSION);#endif#ifdef MODULE_LICENSEMODULE_LICENSE("Dual BSD/GPL");#endifstatic int __initinit_ath_rate_sample(void){	return ieee80211_rate_register(&ath_rate_ops);}module_init(init_ath_rate_sample);static void __exitexit_ath_rate_sample(void){	ieee80211_rate_unregister(&ath_rate_ops);}module_exit(exit_ath_rate_sample);

⌨️ 快捷键说明

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