xref: /dflybsd-src/sys/netproto/802_11/ieee80211_ratectl.h (revision 805c8e8e4093ceca2e27510ad3a66d4de8060a55)
14028af95SRui Paulo /*-
24028af95SRui Paulo  * Copyright (c) 2010 Rui Paulo <rpaulo@FreeBSD.org>
34028af95SRui Paulo  * All rights reserved.
4b9334f94SSepherosa Ziehau  *
5b9334f94SSepherosa Ziehau  * Redistribution and use in source and binary forms, with or without
6b9334f94SSepherosa Ziehau  * modification, are permitted provided that the following conditions
7b9334f94SSepherosa Ziehau  * are met:
8b9334f94SSepherosa Ziehau  * 1. Redistributions of source code must retain the above copyright
9b9334f94SSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer.
10b9334f94SSepherosa Ziehau  * 2. Redistributions in binary form must reproduce the above copyright
114028af95SRui Paulo  *    notice, this list of conditions and the following disclaimer in the
124028af95SRui Paulo  *    documentation and/or other materials provided with the distribution.
13b9334f94SSepherosa Ziehau  *
144028af95SRui Paulo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
154028af95SRui Paulo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
164028af95SRui Paulo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
174028af95SRui Paulo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
184028af95SRui Paulo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
194028af95SRui Paulo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
204028af95SRui Paulo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
214028af95SRui Paulo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
224028af95SRui Paulo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
234028af95SRui Paulo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24b9334f94SSepherosa Ziehau  *
25085ff963SMatthew Dillon  * $FreeBSD$
26b9334f94SSepherosa Ziehau  */
27b9334f94SSepherosa Ziehau 
284028af95SRui Paulo enum ieee80211_ratealgs {
294028af95SRui Paulo 	IEEE80211_RATECTL_AMRR		= 0,
304028af95SRui Paulo 	IEEE80211_RATECTL_RSSADAPT	= 1,
314028af95SRui Paulo 	IEEE80211_RATECTL_ONOE		= 2,
324028af95SRui Paulo 	IEEE80211_RATECTL_SAMPLE	= 3,
3316878352SSascha Wildner 	IEEE80211_RATECTL_NONE		= 4,
344028af95SRui Paulo 	IEEE80211_RATECTL_MAX
35b9334f94SSepherosa Ziehau };
36b9334f94SSepherosa Ziehau 
37085ff963SMatthew Dillon #define	IEEE80211_RATECTL_TX_SUCCESS	1
38085ff963SMatthew Dillon #define	IEEE80211_RATECTL_TX_FAILURE	0
397fdf07d2SSepherosa Ziehau 
40b9334f94SSepherosa Ziehau struct ieee80211_ratectl {
414028af95SRui Paulo 	const char *ir_name;
424028af95SRui Paulo 	int	(*ir_attach)(const struct ieee80211vap *);
434028af95SRui Paulo 	void	(*ir_detach)(const struct ieee80211vap *);
444028af95SRui Paulo 	void	(*ir_init)(struct ieee80211vap *);
454028af95SRui Paulo 	void	(*ir_deinit)(struct ieee80211vap *);
464028af95SRui Paulo 	void	(*ir_node_init)(struct ieee80211_node *);
474028af95SRui Paulo 	void	(*ir_node_deinit)(struct ieee80211_node *);
484028af95SRui Paulo 	int	(*ir_rate)(struct ieee80211_node *, void *, uint32_t);
494028af95SRui Paulo 	void	(*ir_tx_complete)(const struct ieee80211vap *,
504028af95SRui Paulo 	    			  const struct ieee80211_node *, int,
514028af95SRui Paulo 	    			  void *, void *);
524028af95SRui Paulo 	void	(*ir_tx_update)(const struct ieee80211vap *,
534028af95SRui Paulo 	    			const struct ieee80211_node *,
544028af95SRui Paulo 	    			void *, void *, void *);
554028af95SRui Paulo 	void	(*ir_setinterval)(const struct ieee80211vap *, int);
564f655ef5SMatthew Dillon 	void	(*ir_node_stats)(struct ieee80211_node *ni, struct sbuf *s);
57b9334f94SSepherosa Ziehau };
58b9334f94SSepherosa Ziehau 
594028af95SRui Paulo void	ieee80211_ratectl_register(int, const struct ieee80211_ratectl *);
604028af95SRui Paulo void	ieee80211_ratectl_unregister(int);
6116878352SSascha Wildner void	ieee80211_ratectl_init(struct ieee80211vap *);
624028af95SRui Paulo void	ieee80211_ratectl_set(struct ieee80211vap *, int);
630dba45feSSepherosa Ziehau 
64*805c8e8eSzrj #ifdef MALLOC_DECLARE
654028af95SRui Paulo MALLOC_DECLARE(M_80211_RATECTL);
66*805c8e8eSzrj #endif
670dba45feSSepherosa Ziehau 
68db11cb20SSascha Wildner static __inline void
ieee80211_ratectl_deinit(struct ieee80211vap * vap)694028af95SRui Paulo ieee80211_ratectl_deinit(struct ieee80211vap *vap)
704028af95SRui Paulo {
714028af95SRui Paulo 	vap->iv_rate->ir_deinit(vap);
724028af95SRui Paulo }
73b9334f94SSepherosa Ziehau 
74db11cb20SSascha Wildner static __inline void
ieee80211_ratectl_node_init(struct ieee80211_node * ni)754028af95SRui Paulo ieee80211_ratectl_node_init(struct ieee80211_node *ni)
764028af95SRui Paulo {
774028af95SRui Paulo 	const struct ieee80211vap *vap = ni->ni_vap;
78b9334f94SSepherosa Ziehau 
794028af95SRui Paulo 	vap->iv_rate->ir_node_init(ni);
804028af95SRui Paulo }
81b9334f94SSepherosa Ziehau 
82db11cb20SSascha Wildner static __inline void
ieee80211_ratectl_node_deinit(struct ieee80211_node * ni)834028af95SRui Paulo ieee80211_ratectl_node_deinit(struct ieee80211_node *ni)
844028af95SRui Paulo {
854028af95SRui Paulo 	const struct ieee80211vap *vap = ni->ni_vap;
86a13825b3SRui Paulo 
874028af95SRui Paulo 	vap->iv_rate->ir_node_deinit(ni);
884028af95SRui Paulo }
89b9334f94SSepherosa Ziehau 
90db11cb20SSascha Wildner static __inline int
ieee80211_ratectl_rate(struct ieee80211_node * ni,void * arg,uint32_t iarg)914028af95SRui Paulo ieee80211_ratectl_rate(struct ieee80211_node *ni, void *arg, uint32_t iarg)
924028af95SRui Paulo {
934028af95SRui Paulo 	const struct ieee80211vap *vap = ni->ni_vap;
94b9334f94SSepherosa Ziehau 
954028af95SRui Paulo 	return vap->iv_rate->ir_rate(ni, arg, iarg);
964028af95SRui Paulo }
97b9334f94SSepherosa Ziehau 
98db11cb20SSascha Wildner static __inline void
ieee80211_ratectl_tx_complete(const struct ieee80211vap * vap,const struct ieee80211_node * ni,int status,void * arg1,void * arg2)994028af95SRui Paulo ieee80211_ratectl_tx_complete(const struct ieee80211vap *vap,
1004028af95SRui Paulo     const struct ieee80211_node *ni, int status, void *arg1, void *arg2)
1014028af95SRui Paulo {
1024028af95SRui Paulo 	vap->iv_rate->ir_tx_complete(vap, ni, status, arg1, arg2);
1034028af95SRui Paulo }
104b9334f94SSepherosa Ziehau 
105db11cb20SSascha Wildner static __inline void
ieee80211_ratectl_tx_update(const struct ieee80211vap * vap,const struct ieee80211_node * ni,void * arg1,void * arg2,void * arg3)1064028af95SRui Paulo ieee80211_ratectl_tx_update(const struct ieee80211vap *vap,
1074028af95SRui Paulo     const struct ieee80211_node *ni, void *arg1, void *arg2, void *arg3)
1084028af95SRui Paulo {
1094028af95SRui Paulo 	if (vap->iv_rate->ir_tx_update == NULL)
1104028af95SRui Paulo 		return;
1114028af95SRui Paulo 	vap->iv_rate->ir_tx_update(vap, ni, arg1, arg2, arg3);
1124028af95SRui Paulo }
113b9334f94SSepherosa Ziehau 
114db11cb20SSascha Wildner static __inline void
ieee80211_ratectl_setinterval(const struct ieee80211vap * vap,int msecs)1154028af95SRui Paulo ieee80211_ratectl_setinterval(const struct ieee80211vap *vap, int msecs)
1164028af95SRui Paulo {
1174028af95SRui Paulo 	if (vap->iv_rate->ir_setinterval == NULL)
1184028af95SRui Paulo 		return;
1194028af95SRui Paulo 	vap->iv_rate->ir_setinterval(vap, msecs);
1204028af95SRui Paulo }
1214f655ef5SMatthew Dillon 
1224f655ef5SMatthew Dillon static __inline void
ieee80211_ratectl_node_stats(struct ieee80211_node * ni,struct sbuf * s)1234f655ef5SMatthew Dillon ieee80211_ratectl_node_stats(struct ieee80211_node *ni, struct sbuf *s)
1244f655ef5SMatthew Dillon {
1254f655ef5SMatthew Dillon 	const struct ieee80211vap *vap = ni->ni_vap;
1264f655ef5SMatthew Dillon 
1274f655ef5SMatthew Dillon 	if (vap->iv_rate->ir_node_stats == NULL)
1284f655ef5SMatthew Dillon 		return;
1294f655ef5SMatthew Dillon 	vap->iv_rate->ir_node_stats(ni, s);
1304f655ef5SMatthew Dillon }
131