1*bb6f7ec3Sroy /* $NetBSD: ieee80211_rssadapt.h,v 1.9 2016/04/08 14:30:47 roy Exp $ */ 29c65c69cSdyoung /*- 39c65c69cSdyoung * Copyright (c) 2003, 2004 David Young. All rights reserved. 49c65c69cSdyoung * 59c65c69cSdyoung * Redistribution and use in source and binary forms, with or 69c65c69cSdyoung * without modification, are permitted provided that the following 79c65c69cSdyoung * conditions are met: 89c65c69cSdyoung * 1. Redistributions of source code must retain the above copyright 99c65c69cSdyoung * notice, this list of conditions and the following disclaimer. 109c65c69cSdyoung * 2. Redistributions in binary form must reproduce the above 119c65c69cSdyoung * copyright notice, this list of conditions and the following 129c65c69cSdyoung * disclaimer in the documentation and/or other materials provided 139c65c69cSdyoung * with the distribution. 149c65c69cSdyoung * 159c65c69cSdyoung * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY 169c65c69cSdyoung * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 179c65c69cSdyoung * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 189c65c69cSdyoung * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David 199c65c69cSdyoung * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 209c65c69cSdyoung * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 219c65c69cSdyoung * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 229c65c69cSdyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 239c65c69cSdyoung * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 249c65c69cSdyoung * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 259c65c69cSdyoung * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 269c65c69cSdyoung * OF SUCH DAMAGE. 279c65c69cSdyoung */ 289c65c69cSdyoung 29976bf6cfSelad #ifndef _NET80211_IEEE80211_RSSADAPT_H_ 30976bf6cfSelad #define _NET80211_IEEE80211_RSSADAPT_H_ 31976bf6cfSelad 329c65c69cSdyoung /* Data-rate adaptation loosely based on "Link Adaptation Strategy 339c65c69cSdyoung * for IEEE 802.11 WLAN via Received Signal Strength Measurement" 349c65c69cSdyoung * by Javier del Prado Pavon and Sunghyun Choi. 359c65c69cSdyoung */ 369c65c69cSdyoung 379c65c69cSdyoung /* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */ 389c65c69cSdyoung #define IEEE80211_RSSADAPT_BKTS 3 399c65c69cSdyoung #define IEEE80211_RSSADAPT_BKT0 128 409c65c69cSdyoung #define IEEE80211_RSSADAPT_BKTPOWER 3 /* 2**_BKTPOWER */ 419c65c69cSdyoung 429c65c69cSdyoung #define ieee80211_rssadapt_thresh_new \ 439c65c69cSdyoung (ieee80211_rssadapt_thresh_denom - ieee80211_rssadapt_thresh_old) 449c65c69cSdyoung #define ieee80211_rssadapt_decay_new \ 459c65c69cSdyoung (ieee80211_rssadapt_decay_denom - ieee80211_rssadapt_decay_old) 469c65c69cSdyoung #define ieee80211_rssadapt_avgrssi_new \ 479c65c69cSdyoung (ieee80211_rssadapt_avgrssi_denom - ieee80211_rssadapt_avgrssi_old) 489c65c69cSdyoung 4973a618d5Sdyoung struct ieee80211_rssadapt_expavgctl { 5073a618d5Sdyoung /* RSS threshold decay. */ 5173a618d5Sdyoung u_int rc_decay_denom; 5273a618d5Sdyoung u_int rc_decay_old; 5373a618d5Sdyoung /* RSS threshold update. */ 5473a618d5Sdyoung u_int rc_thresh_denom; 5573a618d5Sdyoung u_int rc_thresh_old; 5673a618d5Sdyoung /* RSS average update. */ 5773a618d5Sdyoung u_int rc_avgrssi_denom; 5873a618d5Sdyoung u_int rc_avgrssi_old; 5973a618d5Sdyoung }; 6073a618d5Sdyoung 619c65c69cSdyoung struct ieee80211_rssadapt { 629c65c69cSdyoung /* exponential average RSSI << 8 */ 639c65c69cSdyoung u_int16_t ra_avg_rssi; 649c65c69cSdyoung /* Tx failures in this update interval */ 659c65c69cSdyoung u_int32_t ra_nfail; 669c65c69cSdyoung /* Tx successes in this update interval */ 679c65c69cSdyoung u_int32_t ra_nok; 689c65c69cSdyoung /* exponential average packets/second */ 699c65c69cSdyoung u_int32_t ra_pktrate; 709c65c69cSdyoung /* RSSI threshold for each Tx rate */ 719c65c69cSdyoung u_int16_t ra_rate_thresh[IEEE80211_RSSADAPT_BKTS] 729c65c69cSdyoung [IEEE80211_RATE_SIZE]; 739c65c69cSdyoung struct timeval ra_last_raise; 749c65c69cSdyoung struct timeval ra_raise_interval; 759c65c69cSdyoung }; 769c65c69cSdyoung 779c65c69cSdyoung /* Properties of a Tx packet, for link adaptation. */ 789c65c69cSdyoung struct ieee80211_rssdesc { 799c65c69cSdyoung u_int id_len; /* Tx packet length */ 809c65c69cSdyoung u_int id_rateidx; /* index into ni->ni_rates */ 819c65c69cSdyoung struct ieee80211_node *id_node; /* destination STA MAC */ 82*bb6f7ec3Sroy u_int8_t id_rssi; /* destination STA avg RSS @ 839c65c69cSdyoung * Tx time 849c65c69cSdyoung */ 859c65c69cSdyoung }; 869c65c69cSdyoung 879c65c69cSdyoung void ieee80211_rssadapt_updatestats(struct ieee80211_rssadapt *); 889c65c69cSdyoung void ieee80211_rssadapt_input(struct ieee80211com *, struct ieee80211_node *, 899c65c69cSdyoung struct ieee80211_rssadapt *, int); 909c65c69cSdyoung void ieee80211_rssadapt_lower_rate(struct ieee80211com *, 919c65c69cSdyoung struct ieee80211_node *, struct ieee80211_rssadapt *, 929c65c69cSdyoung struct ieee80211_rssdesc *); 939c65c69cSdyoung void ieee80211_rssadapt_raise_rate(struct ieee80211com *, 949c65c69cSdyoung struct ieee80211_rssadapt *, struct ieee80211_rssdesc *); 9573a618d5Sdyoung int ieee80211_rssadapt_choose(struct ieee80211_rssadapt *, 9673a618d5Sdyoung struct ieee80211_rateset *, struct ieee80211_frame *, u_int, int, 9773a618d5Sdyoung const char *, int); 987c84c56eSdyoung #ifdef IEEE80211_DEBUG 997c84c56eSdyoung extern int ieee80211_rssadapt_debug; 1007c84c56eSdyoung #endif /* IEEE80211_DEBUG */ 101976bf6cfSelad 102976bf6cfSelad #endif /* !_NET80211_IEEE80211_RSSADAPT_H_ */ 103976bf6cfSelad 104