2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2010 Rui Paulo <rpaulo@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
30 #ifndef _NET80211_IEEE80211_RATECTL_H_
31 #define _NET80211_IEEE80211_RATECTL_H_
33 enum ieee80211_ratealgs {
34 IEEE80211_RATECTL_AMRR = 0,
35 IEEE80211_RATECTL_RSSADAPT = 1,
36 IEEE80211_RATECTL_ONOE = 2,
37 IEEE80211_RATECTL_SAMPLE = 3,
38 IEEE80211_RATECTL_NONE = 4,
42 /* used fields for tx_complete() events */
43 #define IEEE80211_RATECTL_STATUS_PKTLEN 0x00000001
44 #define IEEE80211_RATECTL_STATUS_FINAL_RATE 0x00000002
45 #define IEEE80211_RATECTL_STATUS_SHORT_RETRY 0x00000004
46 #define IEEE80211_RATECTL_STATUS_LONG_RETRY 0x00000008
47 #define IEEE80211_RATECTL_STATUS_RSSI 0x00000010
50 enum ieee80211_ratectl_tx_fail_reason {
51 IEEE80211_RATECTL_TX_SUCCESS = 0,
52 IEEE80211_RATECTL_TX_FAIL_SHORT = 1, /* too many RTS retries */
53 IEEE80211_RATECTL_TX_FAIL_LONG = 2, /* too many retries */
54 IEEE80211_RATECTL_TX_FAIL_EXPIRED = 3, /* lifetime expired */
55 IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED = 4, /* another reason */
57 #define IEEE80211_RATECTL_TX_FAIL_MAX \
58 (IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED + 1)
60 struct ieee80211_ratectl_tx_status {
61 uint32_t flags; /* mark used fields */
62 enum ieee80211_ratectl_tx_fail_reason status; /* Tx status */
64 int pktlen; /* frame length */
65 int final_rate; /* transmission rate */
66 uint_fast8_t short_retries; /* RTS/CTS retries */
67 uint_fast8_t long_retries; /* ACK retries */
68 int8_t rssi; /* ACK RSSI */
70 uint8_t spare[15]; /* for future use */
73 /* used fields for tx_update() events */
74 #define IEEE80211_RATECTL_TX_STATS_NODE 0x00000001
75 #define IEEE80211_RATECTL_TX_STATS_RETRIES 0x00000002
77 struct ieee80211_ratectl_tx_stats {
78 uint32_t flags; /* mark used fields */
80 struct ieee80211_node *ni; /* receiver */
81 int nframes; /* transmitted frames */
82 int nsuccess; /* ACKed frames */
83 int nretries; /* number of retries */
86 struct ieee80211_ratectl {
88 int (*ir_attach)(const struct ieee80211vap *);
89 void (*ir_detach)(const struct ieee80211vap *);
90 void (*ir_init)(struct ieee80211vap *);
91 void (*ir_deinit)(struct ieee80211vap *);
92 void (*ir_node_init)(struct ieee80211_node *);
93 void (*ir_node_deinit)(struct ieee80211_node *);
94 int (*ir_rate)(struct ieee80211_node *, void *, uint32_t);
95 void (*ir_tx_complete)(const struct ieee80211_node *,
96 const struct ieee80211_ratectl_tx_status *);
97 void (*ir_tx_update)(struct ieee80211vap *,
98 struct ieee80211_ratectl_tx_stats *);
99 void (*ir_setinterval)(const struct ieee80211vap *, int);
100 void (*ir_node_stats)(struct ieee80211_node *ni, struct sbuf *s);
103 void ieee80211_ratectl_register(int, const struct ieee80211_ratectl *);
104 void ieee80211_ratectl_unregister(int);
105 void ieee80211_ratectl_init(struct ieee80211vap *);
106 void ieee80211_ratectl_set(struct ieee80211vap *, int);
108 MALLOC_DECLARE(M_80211_RATECTL);
111 ieee80211_ratectl_deinit(struct ieee80211vap *vap)
113 vap->iv_rate->ir_deinit(vap);
117 ieee80211_ratectl_node_init(struct ieee80211_node *ni)
119 const struct ieee80211vap *vap = ni->ni_vap;
121 vap->iv_rate->ir_node_init(ni);
125 ieee80211_ratectl_node_deinit(struct ieee80211_node *ni)
127 const struct ieee80211vap *vap = ni->ni_vap;
129 vap->iv_rate->ir_node_deinit(ni);
133 ieee80211_ratectl_rate(struct ieee80211_node *ni, void *arg, uint32_t iarg)
135 const struct ieee80211vap *vap = ni->ni_vap;
137 return vap->iv_rate->ir_rate(ni, arg, iarg);
141 ieee80211_ratectl_tx_complete(const struct ieee80211_node *ni,
142 const struct ieee80211_ratectl_tx_status *status)
144 const struct ieee80211vap *vap = ni->ni_vap;
146 vap->iv_rate->ir_tx_complete(ni, status);
150 ieee80211_ratectl_tx_update(struct ieee80211vap *vap,
151 struct ieee80211_ratectl_tx_stats *stats)
153 if (vap->iv_rate->ir_tx_update == NULL)
155 vap->iv_rate->ir_tx_update(vap, stats);
159 ieee80211_ratectl_setinterval(const struct ieee80211vap *vap, int msecs)
161 if (vap->iv_rate->ir_setinterval == NULL)
163 vap->iv_rate->ir_setinterval(vap, msecs);
167 ieee80211_ratectl_node_stats(struct ieee80211_node *ni, struct sbuf *s)
169 const struct ieee80211vap *vap = ni->ni_vap;
171 if (vap->iv_rate->ir_node_stats == NULL)
173 vap->iv_rate->ir_node_stats(ni, s);
176 #endif /* _NET80211_IEEE80211_RATECTL_H_ */