10SN/A/* $OpenBSD: ieee80211_rssadapt.h,v 1.5 2010/07/17 16:25:09 damien Exp $ */
22362SN/A/* $NetBSD: ieee80211_rssadapt.h,v 1.3 2004/05/06 03:03:20 dyoung Exp $ */
30SN/A
40SN/A/*-
50SN/A * Copyright (c) 2003, 2004 David Young.  All rights reserved.
60SN/A *
72362SN/A * Redistribution and use in source and binary forms, with or
80SN/A * without modification, are permitted provided that the following
92362SN/A * conditions are met:
100SN/A * 1. Redistributions of source code must retain the above copyright
110SN/A *    notice, this list of conditions and the following disclaimer.
120SN/A * 2. Redistributions in binary form must reproduce the above
130SN/A *    copyright notice, this list of conditions and the following
140SN/A *    disclaimer in the documentation and/or other materials provided
150SN/A *    with the distribution.
160SN/A *
170SN/A * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
180SN/A * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
190SN/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
200SN/A * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL David
212362SN/A * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
222362SN/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
232362SN/A * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
240SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
250SN/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
260SN/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
270SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
280SN/A * OF SUCH DAMAGE.
290SN/A */
300SN/A#ifndef _NET80211_IEEE80211_RSSADAPT_H_
310SN/A#define _NET80211_IEEE80211_RSSADAPT_H_
320SN/A
330SN/A/* Data-rate adaptation loosely based on "Link Adaptation Strategy
340SN/A * for IEEE 802.11 WLAN via Received Signal Strength Measurement"
350SN/A * by Javier del Prado Pavon and Sunghyun Choi.
360SN/A */
370SN/A
380SN/A/* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */
390SN/A#define	IEEE80211_RSSADAPT_BKTS		3
400SN/A#define IEEE80211_RSSADAPT_BKT0		128
410SN/A#define	IEEE80211_RSSADAPT_BKTPOWER	3	/* 2**_BKTPOWER */
420SN/A
430SN/A#define	ieee80211_rssadapt_thresh_new \
440SN/A    (ieee80211_rssadapt_thresh_denom - ieee80211_rssadapt_thresh_old)
450SN/A#define	ieee80211_rssadapt_decay_new \
460SN/A    (ieee80211_rssadapt_decay_denom - ieee80211_rssadapt_decay_old)
470SN/A#define	ieee80211_rssadapt_avgrssi_new \
480SN/A    (ieee80211_rssadapt_avgrssi_denom - ieee80211_rssadapt_avgrssi_old)
490SN/A
500SN/Astruct ieee80211_rssadapt_expavgctl {
510SN/A	/* RSS threshold decay. */
520SN/A	u_int rc_decay_denom;
530SN/A	u_int rc_decay_old;
540SN/A	/* RSS threshold update. */
550SN/A	u_int rc_thresh_denom;
560SN/A	u_int rc_thresh_old;
570SN/A	/* RSS average update. */
580SN/A	u_int rc_avgrssi_denom;
590SN/A	u_int rc_avgrssi_old;
600SN/A};
610SN/A
620SN/Astruct ieee80211_rssadapt {
630SN/A	/* exponential average RSSI << 8 */
640SN/A	u_int16_t		ra_avg_rssi;
650SN/A	/* Tx failures in this update interval */
660SN/A	u_int32_t		ra_nfail;
670SN/A	/* Tx successes in this update interval */
680SN/A	u_int32_t		ra_nok;
690SN/A	/* exponential average packets/second */
700SN/A	u_int32_t		ra_pktrate;
710SN/A	/* RSSI threshold for each Tx rate */
720SN/A	u_int16_t		ra_rate_thresh[IEEE80211_RSSADAPT_BKTS]
730SN/A				    [IEEE80211_RATE_SIZE];
740SN/A	struct timeval		ra_last_raise;
750SN/A	struct timeval		ra_raise_interval;
760SN/A};
770SN/A
780SN/A/* Properties of a Tx packet, for link adaptation. */
790SN/Astruct ieee80211_rssdesc {
800SN/A	u_int			 id_len;	/* Tx packet length */
810SN/A	u_int			 id_rateidx;	/* index into ni->ni_rates */
820SN/A	struct ieee80211_node	*id_node;	/* destination STA MAC */
830SN/A	u_int8_t		 id_rssi;	/* destination STA avg RSS @
840SN/A						 * Tx time
850SN/A						 */
860SN/A};
870SN/A
880SN/Avoid	ieee80211_rssadapt_updatestats(struct ieee80211_rssadapt *);
890SN/Avoid	ieee80211_rssadapt_input(struct ieee80211com *,
900SN/A	    const struct ieee80211_node *, struct ieee80211_rssadapt *, int);
910SN/Avoid	ieee80211_rssadapt_lower_rate(struct ieee80211com *,
920SN/A	    const struct ieee80211_node *, struct ieee80211_rssadapt *,
93430SN/A	    const struct ieee80211_rssdesc *);
94430SN/Avoid	ieee80211_rssadapt_raise_rate(struct ieee80211com *,
95430SN/A	    struct ieee80211_rssadapt *, const struct ieee80211_rssdesc *);
96430SN/Aint	ieee80211_rssadapt_choose(struct ieee80211_rssadapt *,
97430SN/A	    const struct ieee80211_rateset *, const struct ieee80211_frame *,
98430SN/A	    u_int, int, const char *, int);
99430SN/A#ifdef IEEE80211_DEBUG
1000SN/Aextern int ieee80211_rssadapt_debug;
1010SN/A#endif /* IEEE80211_DEBUG */
1020SN/A
1030SN/A#endif /* _NET80211_IEEE80211_RSSADAPT_H_ */
1040SN/A