master
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2010 Rui Paulo <rpaulo@FreeBSD.org>
5 * All rights reserved.
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 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef _NET80211_IEEE80211_RATECTL_H_
29#define _NET80211_IEEE80211_RATECTL_H_
30
31enum ieee80211_ratealgs {
32 IEEE80211_RATECTL_AMRR = 0,
33 IEEE80211_RATECTL_RSSADAPT = 1,
34 IEEE80211_RATECTL_ONOE = 2,
35 IEEE80211_RATECTL_SAMPLE = 3,
36 IEEE80211_RATECTL_NONE = 4,
37 IEEE80211_RATECTL_MAX
38};
39
40/* used fields for tx_complete() events */
41#define IEEE80211_RATECTL_STATUS_PKTLEN 0x00000001
42#define IEEE80211_RATECTL_STATUS_FINAL_RATE 0x00000002
43#define IEEE80211_RATECTL_STATUS_SHORT_RETRY 0x00000004
44#define IEEE80211_RATECTL_STATUS_LONG_RETRY 0x00000008
45#define IEEE80211_RATECTL_STATUS_RSSI 0x00000010
46
47/* failure reason */
48enum ieee80211_ratectl_tx_fail_reason {
49 IEEE80211_RATECTL_TX_SUCCESS = 0,
50 IEEE80211_RATECTL_TX_FAIL_SHORT = 1, /* too many RTS retries */
51 IEEE80211_RATECTL_TX_FAIL_LONG = 2, /* too many retries */
52 IEEE80211_RATECTL_TX_FAIL_EXPIRED = 3, /* lifetime expired */
53 IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED = 4, /* another reason */
54};
55#define IEEE80211_RATECTL_TX_FAIL_MAX \
56 (IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED + 1)
57
58struct ieee80211_ratectl_tx_status {
59 uint32_t flags; /* mark used fields */
60 enum ieee80211_ratectl_tx_fail_reason status; /* Tx status */
61
62 int pktlen; /* frame length */
63 int final_rate; /* transmission rate */
64 uint_fast8_t short_retries; /* RTS/CTS retries */
65 uint_fast8_t long_retries; /* ACK retries */
66 int8_t rssi; /* ACK RSSI */
67
68 uint8_t spare[15]; /* for future use */
69};
70
71/* used fields for tx_update() events */
72#define IEEE80211_RATECTL_TX_STATS_NODE 0x00000001
73#define IEEE80211_RATECTL_TX_STATS_RETRIES 0x00000002
74
75struct ieee80211_ratectl_tx_stats {
76 uint32_t flags; /* mark used fields */
77
78 struct ieee80211_node *ni; /* receiver */
79 int nframes; /* transmitted frames */
80 int nsuccess; /* ACKed frames */
81 int nretries; /* number of retries */
82};
83
84struct ieee80211_ratectl {
85 const char *ir_name;
86 int (*ir_attach)(const struct ieee80211vap *);
87 void (*ir_detach)(const struct ieee80211vap *);
88 void (*ir_init)(struct ieee80211vap *);
89 void (*ir_deinit)(struct ieee80211vap *);
90 void (*ir_node_init)(struct ieee80211_node *);
91 void (*ir_node_deinit)(struct ieee80211_node *);
92 int (*ir_rate)(struct ieee80211_node *, void *, uint32_t);
93 void (*ir_tx_complete)(const struct ieee80211_node *,
94 const struct ieee80211_ratectl_tx_status *);
95 void (*ir_tx_update)(struct ieee80211vap *,
96 struct ieee80211_ratectl_tx_stats *);
97 void (*ir_setinterval)(const struct ieee80211vap *, int);
98 void (*ir_node_stats)(struct ieee80211_node *ni, struct sbuf *s);
99};
100
101void ieee80211_ratectl_register(int, const struct ieee80211_ratectl *);
102void ieee80211_ratectl_unregister(int);
103void ieee80211_ratectl_init(struct ieee80211vap *);
104void ieee80211_ratectl_set(struct ieee80211vap *, int);
105
106MALLOC_DECLARE(M_80211_RATECTL);
107
108static __inline void
109ieee80211_ratectl_deinit(struct ieee80211vap *vap)
110{
111 vap->iv_rate->ir_deinit(vap);
112}
113
114static __inline void
115ieee80211_ratectl_node_init(struct ieee80211_node *ni)
116{
117 const struct ieee80211vap *vap = ni->ni_vap;
118
119 vap->iv_rate->ir_node_init(ni);
120}
121
122static __inline void
123ieee80211_ratectl_node_deinit(struct ieee80211_node *ni)
124{
125 const struct ieee80211vap *vap = ni->ni_vap;
126
127 vap->iv_rate->ir_node_deinit(ni);
128}
129
130static int __inline
131ieee80211_ratectl_rate(struct ieee80211_node *ni, void *arg, uint32_t iarg)
132{
133 const struct ieee80211vap *vap = ni->ni_vap;
134
135 return vap->iv_rate->ir_rate(ni, arg, iarg);
136}
137
138static __inline void
139ieee80211_ratectl_tx_complete(const struct ieee80211_node *ni,
140 const struct ieee80211_ratectl_tx_status *status)
141{
142 const struct ieee80211vap *vap = ni->ni_vap;
143
144 vap->iv_rate->ir_tx_complete(ni, status);
145}
146
147static __inline void
148ieee80211_ratectl_tx_update(struct ieee80211vap *vap,
149 struct ieee80211_ratectl_tx_stats *stats)
150{
151 if (vap->iv_rate->ir_tx_update == NULL)
152 return;
153 vap->iv_rate->ir_tx_update(vap, stats);
154}
155
156static __inline void
157ieee80211_ratectl_setinterval(const struct ieee80211vap *vap, int msecs)
158{
159 if (vap->iv_rate->ir_setinterval == NULL)
160 return;
161 vap->iv_rate->ir_setinterval(vap, msecs);
162}
163
164static __inline void
165ieee80211_ratectl_node_stats(struct ieee80211_node *ni, struct sbuf *s)
166{
167 const struct ieee80211vap *vap = ni->ni_vap;
168
169 if (vap->iv_rate->ir_node_stats == NULL)
170 return;
171 vap->iv_rate->ir_node_stats(ni, s);
172}
173
174#endif /* _NET80211_IEEE80211_RATECTL_H_ */