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