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