]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/ral/if_ralrate.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / ral / if_ralrate.h
1 /*      $FreeBSD$       */
2 /* $NetBSD: ieee80211_rssadapt.h,v 1.4 2005/02/26 22:45:09 perry Exp $ */
3 /*-
4  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or
7  * without modification, are permitted provided that the following
8  * conditions are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above
12  *    copyright notice, this list of conditions and the following
13  *    disclaimer in the documentation and/or other materials provided
14  *    with the distribution.
15  * 3. The name of David Young may not be used to endorse or promote
16  *    products derived from this software without specific prior
17  *    written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
20  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL David
23  * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  */
32
33 /* Data-rate adaptation loosely based on "Link Adaptation Strategy
34  * for IEEE 802.11 WLAN via Received Signal Strength Measurement"
35  * by Javier del Prado Pavon and Sunghyun Choi.
36  */
37
38 /* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */
39 #define RAL_RSSADAPT_BKTS               3
40 #define RAL_RSSADAPT_BKT0               128
41 #define RAL_RSSADAPT_BKTPOWER   3       /* 2**_BKTPOWER */
42
43 #define ral_rssadapt_thresh_new \
44     (ral_rssadapt_thresh_denom - ral_rssadapt_thresh_old)
45 #define ral_rssadapt_decay_new \
46     (ral_rssadapt_decay_denom - ral_rssadapt_decay_old)
47 #define ral_rssadapt_avgrssi_new \
48     (ral_rssadapt_avgrssi_denom - ral_rssadapt_avgrssi_old)
49
50 struct ral_rssadapt_expavgctl {
51         /* RSS threshold decay. */
52         u_int rc_decay_denom;
53         u_int rc_decay_old;
54         /* RSS threshold update. */
55         u_int rc_thresh_denom;
56         u_int rc_thresh_old;
57         /* RSS average update. */
58         u_int rc_avgrssi_denom;
59         u_int rc_avgrssi_old;
60 };
61
62 struct ral_rssadapt {
63         /* exponential average RSSI << 8 */
64         u_int16_t               ra_avg_rssi;
65         /* Tx failures in this update interval */
66         u_int32_t               ra_nfail;
67         /* Tx successes in this update interval */
68         u_int32_t               ra_nok;
69         /* exponential average packets/second */
70         u_int32_t               ra_pktrate;
71         /* RSSI threshold for each Tx rate */
72         u_int16_t               ra_rate_thresh[RAL_RSSADAPT_BKTS]
73                                               [IEEE80211_RATE_SIZE];
74         struct timeval          ra_last_raise;
75         struct timeval          ra_raise_interval;
76 };
77
78 /* Properties of a Tx packet, for link adaptation. */
79 struct ral_rssdesc {
80         u_int                    id_len;        /* Tx packet length */
81         u_int                    id_rateidx;    /* index into ni->ni_rates */
82         struct ieee80211_node   *id_node;       /* destination STA MAC */
83         u_int8_t                 id_rssi;       /* destination STA avg RSS @
84                                                  * Tx time
85                                                  */
86 };
87
88 void    ral_rssadapt_updatestats(struct ral_rssadapt *);
89 void    ral_rssadapt_input(struct ieee80211com *, struct ieee80211_node *,
90             struct ral_rssadapt *, int);
91 void    ral_rssadapt_lower_rate(struct ieee80211com *,
92             struct ieee80211_node *, struct ral_rssadapt *,
93             struct ral_rssdesc *);
94 void    ral_rssadapt_raise_rate(struct ieee80211com *,
95             struct ral_rssadapt *, struct ral_rssdesc *);
96 int     ral_rssadapt_choose(struct ral_rssadapt *,
97             struct ieee80211_rateset *, struct ieee80211_frame *, u_int,
98             const char *, int);