ieee80211_ratectl.h revision 206358
1/*-
2 * Copyright (c) 2010 Rui Paulo <rpaulo@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD: head/sys/net80211/ieee80211_ratectl.h 206358 2010-04-07 15:29:13Z rpaulo $
26 */
27
28enum ieee80211_ratealgs {
29	IEEE80211_RATECTL_AMRR 		= 0,
30	IEEE80211_RATECTL_RSSADAPT	= 1,
31	IEEE80211_RATECTL_ONOE		= 2,
32	IEEE80211_RATECTL_SAMPLE	= 3,
33	IEEE80211_RATECTL_MAX
34};
35
36#define	IEEE80211_RATECTL_TX_SUCCESS	0
37#define	IEEE80211_RATECTL_TX_FAILURE	1
38
39struct ieee80211_ratectl {
40	const char *ir_name;
41	int	(*ir_attach)(const struct ieee80211vap *);
42	void	(*ir_detach)(const struct ieee80211vap *);
43	void	(*ir_init)(struct ieee80211vap *);
44	void	(*ir_deinit)(struct ieee80211vap *);
45	void	(*ir_node_init)(struct ieee80211_node *);
46	void	(*ir_node_deinit)(struct ieee80211_node *);
47	int	(*ir_rate)(struct ieee80211_node *, void *, uint32_t);
48	void	(*ir_tx_complete)(const struct ieee80211vap *,
49	    			  const struct ieee80211_node *, int,
50	    			  void *, void *);
51	void	(*ir_tx_update)(const struct ieee80211vap *,
52	    			const struct ieee80211_node *,
53	    			void *, void *, void *);
54	void	(*ir_setinterval)(const struct ieee80211vap *, int);
55};
56
57void	ieee80211_ratectl_register(int, const struct ieee80211_ratectl *);
58void	ieee80211_ratectl_unregister(int);
59void	ieee80211_ratectl_set(struct ieee80211vap *, int);
60
61MALLOC_DECLARE(M_80211_RATECTL);
62
63static void __inline
64ieee80211_ratectl_init(struct ieee80211vap *vap)
65{
66	vap->iv_rate->ir_init(vap);
67}
68
69static void __inline
70ieee80211_ratectl_deinit(struct ieee80211vap *vap)
71{
72	vap->iv_rate->ir_deinit(vap);
73}
74
75static void __inline
76ieee80211_ratectl_node_init(struct ieee80211_node *ni)
77{
78	const struct ieee80211vap *vap = ni->ni_vap;
79
80	vap->iv_rate->ir_node_init(ni);
81}
82
83static void __inline
84ieee80211_ratectl_node_deinit(struct ieee80211_node *ni)
85{
86	const struct ieee80211vap *vap = ni->ni_vap;
87
88	vap->iv_rate->ir_node_deinit(ni);
89}
90
91static int __inline
92ieee80211_ratectl_rate(struct ieee80211_node *ni, void *arg, uint32_t iarg)
93{
94	const struct ieee80211vap *vap = ni->ni_vap;
95
96	if (ni->ni_rctls == NULL)	/* ratectl not setup */
97		return;
98	return vap->iv_rate->ir_rate(ni, arg, iarg);
99}
100
101static void __inline
102ieee80211_ratectl_tx_complete(const struct ieee80211vap *vap,
103    const struct ieee80211_node *ni, int status, void *arg1, void *arg2)
104{
105	if (ni->ni_rctls == NULL)	/* ratectl not setup */
106		return;
107	vap->iv_rate->ir_tx_complete(vap, ni, status, arg1, arg2);
108}
109
110static void __inline
111ieee80211_ratectl_tx_update(const struct ieee80211vap *vap,
112    const struct ieee80211_node *ni, void *arg1, void *arg2, void *arg3)
113{
114	if (vap->iv_rate->ir_tx_update == NULL)
115		return;
116	if (ni->ni_rctls == NULL)	/* ratectl not setup */
117		return;
118	vap->iv_rate->ir_tx_update(vap, ni, arg1, arg2, arg3);
119}
120
121static void __inline
122ieee80211_ratectl_setinterval(const struct ieee80211vap *vap, int msecs)
123{
124	if (vap->iv_rate->ir_setinterval == NULL)
125		return;
126	vap->iv_rate->ir_setinterval(vap, msecs);
127}
128