xref: /netbsd-src/sys/net80211/ieee80211_rssadapt.h (revision d20841bb642898112fe68f0ad3f7b26dddf56f07)
1 /* $NetBSD: ieee80211_rssadapt.h,v 1.1 2003/10/26 07:56:41 dyoung Exp $ */
2 /*-
3  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or
6  * without modification, are permitted provided that the following
7  * conditions 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
11  *    copyright notice, this list of conditions and the following
12  *    disclaimer in the documentation and/or other materials provided
13  *    with the distribution.
14  * 3. The name of David Young may not be used to endorse or promote
15  *    products derived from this software without specific prior
16  *    written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL David
22  * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29  * OF SUCH DAMAGE.
30  */
31 
32 /* Data-rate adaptation loosely based on "Link Adaptation Strategy
33  * for IEEE 802.11 WLAN via Received Signal Strength Measurement"
34  * by Javier del Prado Pavon and Sunghyun Choi.
35  */
36 
37 /* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */
38 #define	IEEE80211_RSSADAPT_BKTS		3
39 #define IEEE80211_RSSADAPT_BKT0		128
40 #define	IEEE80211_RSSADAPT_BKTPOWER	3	/* 2**_BKTPOWER */
41 
42 #define	ieee80211_rssadapt_thresh_new \
43     (ieee80211_rssadapt_thresh_denom - ieee80211_rssadapt_thresh_old)
44 #define	ieee80211_rssadapt_decay_new \
45     (ieee80211_rssadapt_decay_denom - ieee80211_rssadapt_decay_old)
46 #define	ieee80211_rssadapt_avgrssi_new \
47     (ieee80211_rssadapt_avgrssi_denom - ieee80211_rssadapt_avgrssi_old)
48 
49 struct ieee80211_rssadapt {
50 	/* exponential average RSSI << 8 */
51 	u_int16_t		ra_avg_rssi;
52 	/* Tx failures in this update interval */
53 	u_int32_t		ra_nfail;
54 	/* Tx successes in this update interval */
55 	u_int32_t		ra_nok;
56 	/* exponential average packets/second */
57 	u_int32_t		ra_pktrate;
58 	/* RSSI threshold for each Tx rate */
59 	u_int16_t		ra_rate_thresh[IEEE80211_RSSADAPT_BKTS]
60 					      [IEEE80211_RATE_SIZE];
61 	struct timeval		ra_last_raise;
62 	struct timeval		ra_raise_interval;
63 };
64 
65 /* Properties of a Tx packet, for link adaptation. */
66 struct ieee80211_rssdesc {
67 	u_int			 id_len;	/* Tx packet length */
68 	u_int			 id_rateidx;	/* index into ni->ni_rates */
69 	struct ieee80211_node	*id_node;	/* destination STA MAC */
70 	u_int8_t		 id_rssi;	/* destination STA avg RSS @
71 						 * Tx time
72 						 */
73 };
74 
75 void	ieee80211_rssadapt_updatestats(struct ieee80211_rssadapt *);
76 void	ieee80211_rssadapt_input(struct ieee80211com *, struct ieee80211_node *,
77 	    struct ieee80211_rssadapt *, int);
78 void	ieee80211_rssadapt_lower_rate(struct ieee80211com *,
79 	    struct ieee80211_node *, struct ieee80211_rssadapt *,
80 	    struct ieee80211_rssdesc *);
81 void	ieee80211_rssadapt_raise_rate(struct ieee80211com *,
82 	    struct ieee80211_rssadapt *, struct ieee80211_rssdesc *);
83 
84