xref: /dflybsd-src/sys/netproto/802_11/ieee80211_ratectl.h (revision 744c01d0dc2aa1481a40e5b0988d15691602f5c9)
1 /*
2  * Copyright (c) 2006 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Sepherosa Ziehau <sepherosa@gmail.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $DragonFly: src/sys/netproto/802_11/ieee80211_ratectl.h,v 1.3 2006/10/24 14:39:44 sephe Exp $
35  */
36 
37 #ifndef _NET80211_IEEE80211_RATECTL_H
38 #define _NET80211_IEEE80211_RATECTL_H
39 
40 struct ieee80211_ratectl_stats;
41 
42 struct ieee80211_ratectl_state {
43 	void		*rc_st_ctx;
44 	void		*rc_st_param;
45 	u_int		rc_st_ratectl;	   /* see IEEE80211_RATECTL_ */
46 	uint32_t	rc_st_ratectl_cap; /* see IEEE80211_RATECTL_CAP_ */
47 	uint64_t	rc_st_valid_stats; /* see IEEE80211_RATECTL_STATS_ */
48 	void		(*rc_st_change)(struct ieee80211com *, u_int, u_int);
49 	void		(*rc_st_stats)(struct ieee80211com *,
50 				       struct ieee80211_node *,
51 				       struct ieee80211_ratectl_stats *);
52 };
53 
54 struct ieee80211_ratectl_res {
55 	int		rc_res_rateidx;
56 	int		rc_res_tries;
57 };
58 
59 #define IEEE80211_RATECTL_STATS_RES		0x1
60 #define IEEE80211_RATECTL_STATS_PKT_NORETRY	0x2
61 #define IEEE80211_RATECTL_STATS_PKT_OK		0x4
62 #define IEEE80211_RATECTL_STATS_PKT_ERR		0x8
63 #define IEEE80211_RATECTL_STATS_RETRIES		0x10
64 
65 #define IEEE80211_RATEIDX_MAX		5
66 
67 struct ieee80211_ratectl_stats {
68 	struct ieee80211_ratectl_res	stats_res[IEEE80211_RATEIDX_MAX];
69 	int				stats_res_len;
70 	int				stats_pkt_noretry;
71 	int				stats_pkt_ok;
72 	int				stats_pkt_err;
73 	int				stats_short_retries;
74 	int				stats_long_retries;
75 };
76 
77 struct ieee80211_ratectl {
78 	const char	*rc_name;
79 	u_int		rc_ratectl;	/* see IEEE80211_RATECTL_ */
80 
81 	void		*(*rc_attach)(struct ieee80211com *);
82 	void		(*rc_detach)(void *);
83 
84 	void		(*rc_data_alloc)(struct ieee80211_node *);
85 	void		(*rc_data_free)(struct ieee80211_node *);
86 	void		(*rc_data_dup)(const struct ieee80211_node *,
87 				       struct ieee80211_node *);
88 
89 	void		(*rc_newstate)(void *, enum ieee80211_state);
90 	void		(*rc_tx_complete)(void *, struct ieee80211_node *, int,
91 					  const struct ieee80211_ratectl_res[],
92 					  int, int, int, int);
93 	void		(*rc_newassoc)(void *, struct ieee80211_node *, int);
94 	int		(*rc_findrate)(void *, struct ieee80211_node *, int,
95 				       int[], int);
96 };
97 
98 #define IEEE80211_RATECTL_NONE		0
99 #define IEEE80211_RATECTL_ONOE		1
100 #define IEEE80211_RATECTL_AMRR		2
101 #define IEEE80211_RATECTL_MAX		3
102 
103 #define IEEE80211_RATECTL_CAP(v)	(1 << (v))
104 
105 #define _IEEE80211_RATECTL_CAP(n)	\
106 	IEEE80211_RATECTL_CAP(IEEE80211_RATECTL_##n)
107 
108 #define IEEE80211_RATECTL_CAP_NONE	_IEEE80211_RATECTL_CAP(NONE)
109 #define IEEE80211_RATECTL_CAP_ONOE	_IEEE80211_RATECTL_CAP(ONOE)
110 #define IEEE80211_RATECTL_CAP_AMRR	_IEEE80211_RATECTL_CAP(AMRR)
111 
112 extern const struct ieee80211_ratectl	ieee80211_ratectl_none;
113 
114 void	ieee80211_ratectl_attach(struct ieee80211com *);
115 void	ieee80211_ratectl_detach(struct ieee80211com *);
116 
117 void	ieee80211_ratectl_register(const struct ieee80211_ratectl *);
118 void	ieee80211_ratectl_unregister(const struct ieee80211_ratectl *);
119 
120 int	ieee80211_ratectl_change(struct ieee80211com *, u_int);
121 
122 void	ieee80211_ratectl_data_alloc(struct ieee80211_node *);
123 void	ieee80211_ratectl_data_dup(const struct ieee80211_node *,
124 				   struct ieee80211_node *);
125 void	ieee80211_ratectl_data_free(struct ieee80211_node *);
126 
127 void	ieee80211_ratectl_newstate(struct ieee80211com *,
128 				   enum ieee80211_state);
129 void	ieee80211_ratectl_tx_complete(struct ieee80211_node *, int,
130 				      const struct ieee80211_ratectl_res[],
131 				      int, int, int, int);
132 void	ieee80211_ratectl_newassoc(struct ieee80211_node *, int);
133 int	ieee80211_ratectl_findrate(struct ieee80211_node *, int, int[], int);
134 
135 #endif	/* !_NET80211_IEEE80211_RATECTL_H */
136