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