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