Home | History | Annotate | Line # | Download | only in net80211
ieee80211_rssadapt.c revision 1.21.16.3
      1  1.21.16.3      phil /*	$NetBSD: ieee80211_rssadapt.c,v 1.21.16.3 2018/07/16 20:11:11 phil Exp $ */
      2  1.21.16.2      phil 
      3        1.1    dyoung /*-
      4  1.21.16.1      phil  * SPDX-License-Identifier: BSD-3-Clause
      5  1.21.16.1      phil  *
      6  1.21.16.1      phil  * Copyright (c) 2010 Rui Paulo <rpaulo (at) FreeBSD.org>
      7        1.1    dyoung  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
      8        1.1    dyoung  *
      9        1.1    dyoung  * Redistribution and use in source and binary forms, with or
     10        1.1    dyoung  * without modification, are permitted provided that the following
     11        1.1    dyoung  * conditions are met:
     12        1.1    dyoung  * 1. Redistributions of source code must retain the above copyright
     13        1.1    dyoung  *    notice, this list of conditions and the following disclaimer.
     14        1.1    dyoung  * 2. Redistributions in binary form must reproduce the above
     15        1.1    dyoung  *    copyright notice, this list of conditions and the following
     16        1.1    dyoung  *    disclaimer in the documentation and/or other materials provided
     17        1.1    dyoung  *    with the distribution.
     18  1.21.16.1      phil  * 3. The name of David Young may not be used to endorse or promote
     19  1.21.16.1      phil  *    products derived from this software without specific prior
     20  1.21.16.1      phil  *    written permission.
     21        1.1    dyoung  *
     22        1.1    dyoung  * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
     23        1.1    dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     24        1.1    dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     25        1.1    dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL David
     26        1.1    dyoung  * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     27        1.1    dyoung  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     28        1.1    dyoung  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29        1.1    dyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     30        1.1    dyoung  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     31        1.1    dyoung  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.1    dyoung  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     33        1.1    dyoung  * OF SUCH DAMAGE.
     34        1.1    dyoung  */
     35  1.21.16.1      phil #include "opt_wlan.h"
     36       1.11    dyoung 
     37        1.1    dyoung #include <sys/param.h>
     38  1.21.16.1      phil #include <sys/systm.h>
     39  1.21.16.1      phil #include <sys/kernel.h>
     40  1.21.16.1      phil #include <sys/malloc.h>
     41  1.21.16.1      phil #include <sys/module.h>
     42  1.21.16.2      phil #ifdef __NetBSD__
     43  1.21.16.2      phil /* Why doesn't FreeBSD have this?  */
     44  1.21.16.2      phil #include <sys/sbuf.h>
     45  1.21.16.2      phil #endif
     46  1.21.16.1      phil #include <sys/socket.h>
     47        1.5    dyoung #include <sys/sysctl.h>
     48        1.1    dyoung 
     49        1.1    dyoung #include <net/if.h>
     50  1.21.16.2      phil #ifdef __FreeBSD__
     51  1.21.16.1      phil #include <net/if_var.h>
     52  1.21.16.2      phil #endif
     53        1.1    dyoung #include <net/if_media.h>
     54  1.21.16.2      phil #ifdef __FreeBSD__
     55  1.21.16.1      phil #include <net/ethernet.h>
     56  1.21.16.2      phil #endif
     57  1.21.16.2      phil #ifdef __NetBSD__
     58  1.21.16.2      phil #include <net/route.h>
     59  1.21.16.2      phil #endif
     60        1.1    dyoung 
     61        1.1    dyoung #include <net80211/ieee80211_var.h>
     62        1.1    dyoung #include <net80211/ieee80211_rssadapt.h>
     63  1.21.16.1      phil #include <net80211/ieee80211_ratectl.h>
     64        1.1    dyoung 
     65  1.21.16.2      phil #ifdef __NetBSD__
     66  1.21.16.2      phil #undef  KASSERT
     67  1.21.16.2      phil #define KASSERT(__cond, __complaint) FBSDKASSERT(__cond, __complaint)
     68  1.21.16.2      phil #endif
     69  1.21.16.2      phil 
     70  1.21.16.1      phil struct rssadapt_expavgctl {
     71  1.21.16.1      phil 	/* RSS threshold decay. */
     72  1.21.16.1      phil 	u_int rc_decay_denom;
     73  1.21.16.1      phil 	u_int rc_decay_old;
     74  1.21.16.1      phil 	/* RSS threshold update. */
     75  1.21.16.1      phil 	u_int rc_thresh_denom;
     76  1.21.16.1      phil 	u_int rc_thresh_old;
     77  1.21.16.1      phil 	/* RSS average update. */
     78  1.21.16.1      phil 	u_int rc_avgrssi_denom;
     79  1.21.16.1      phil 	u_int rc_avgrssi_old;
     80  1.21.16.1      phil };
     81        1.1    dyoung 
     82  1.21.16.1      phil static struct rssadapt_expavgctl master_expavgctl = {
     83       1.15  gmcgarry 	.rc_decay_denom = 16,
     84       1.15  gmcgarry 	.rc_decay_old = 15,
     85       1.15  gmcgarry 	.rc_thresh_denom = 8,
     86       1.15  gmcgarry 	.rc_thresh_old = 4,
     87       1.15  gmcgarry 	.rc_avgrssi_denom = 8,
     88       1.15  gmcgarry 	.rc_avgrssi_old = 4
     89        1.3    dyoung };
     90        1.3    dyoung 
     91  1.21.16.1      phil #ifdef interpolate
     92  1.21.16.1      phil #undef interpolate
     93  1.21.16.1      phil #endif
     94  1.21.16.1      phil #define interpolate(parm, old, new) ((parm##_old * (old) + \
     95  1.21.16.1      phil                                      (parm##_denom - parm##_old) * (new)) / \
     96  1.21.16.1      phil 				    parm##_denom)
     97        1.5    dyoung 
     98  1.21.16.1      phil static void	rssadapt_setinterval(const struct ieee80211vap *, int);
     99  1.21.16.1      phil static void	rssadapt_init(struct ieee80211vap *);
    100  1.21.16.1      phil static void	rssadapt_deinit(struct ieee80211vap *);
    101  1.21.16.1      phil static void	rssadapt_updatestats(struct ieee80211_rssadapt_node *);
    102  1.21.16.1      phil static void	rssadapt_node_init(struct ieee80211_node *);
    103  1.21.16.1      phil static void	rssadapt_node_deinit(struct ieee80211_node *);
    104  1.21.16.1      phil static int	rssadapt_rate(struct ieee80211_node *, void *, uint32_t);
    105  1.21.16.1      phil static void	rssadapt_lower_rate(struct ieee80211_rssadapt_node *, int, int);
    106  1.21.16.1      phil static void	rssadapt_raise_rate(struct ieee80211_rssadapt_node *,
    107  1.21.16.1      phil 			int, int);
    108  1.21.16.1      phil static void	rssadapt_tx_complete(const struct ieee80211_node *,
    109  1.21.16.1      phil 			const struct ieee80211_ratectl_tx_status *);
    110  1.21.16.1      phil static void	rssadapt_sysctlattach(struct ieee80211vap *,
    111  1.21.16.1      phil 			struct sysctl_ctx_list *, struct sysctl_oid *);
    112  1.21.16.1      phil 
    113  1.21.16.1      phil /* number of references from net80211 layer */
    114  1.21.16.1      phil static	int nrefs = 0;
    115  1.21.16.1      phil 
    116  1.21.16.3      phil #if __FreeBSD__
    117  1.21.16.3      phil static const struct ieee80211_ratectl rssadapt = {
    118  1.21.16.3      phil #elif __NetBSD__
    119  1.21.16.3      phil const struct ieee80211_ratectl ratectl_rssadapt = {
    120  1.21.16.3      phil #endif
    121  1.21.16.1      phil 	.ir_name	= "rssadapt",
    122  1.21.16.1      phil 	.ir_attach	= NULL,
    123  1.21.16.1      phil 	.ir_detach	= NULL,
    124  1.21.16.1      phil 	.ir_init	= rssadapt_init,
    125  1.21.16.1      phil 	.ir_deinit	= rssadapt_deinit,
    126  1.21.16.1      phil 	.ir_node_init	= rssadapt_node_init,
    127  1.21.16.1      phil 	.ir_node_deinit	= rssadapt_node_deinit,
    128  1.21.16.1      phil 	.ir_rate	= rssadapt_rate,
    129  1.21.16.1      phil 	.ir_tx_complete	= rssadapt_tx_complete,
    130  1.21.16.1      phil 	.ir_tx_update	= NULL,
    131  1.21.16.1      phil 	.ir_setinterval	= rssadapt_setinterval,
    132  1.21.16.1      phil };
    133  1.21.16.3      phil #if __FreeBSD__
    134  1.21.16.1      phil IEEE80211_RATECTL_MODULE(rssadapt, 1);
    135  1.21.16.1      phil IEEE80211_RATECTL_ALG(rssadapt, IEEE80211_RATECTL_RSSADAPT, rssadapt);
    136  1.21.16.3      phil #endif
    137        1.5    dyoung 
    138  1.21.16.1      phil static void
    139  1.21.16.1      phil rssadapt_setinterval(const struct ieee80211vap *vap, int msecs)
    140  1.21.16.1      phil {
    141  1.21.16.1      phil 	struct ieee80211_rssadapt *rs = vap->iv_rs;
    142  1.21.16.1      phil 	int t;
    143        1.5    dyoung 
    144  1.21.16.1      phil 	if (msecs < 100)
    145  1.21.16.1      phil 		msecs = 100;
    146  1.21.16.1      phil 	t = msecs_to_ticks(msecs);
    147  1.21.16.1      phil 	rs->interval = (t < 1) ? 1 : t;
    148        1.5    dyoung }
    149        1.5    dyoung 
    150  1.21.16.1      phil static void
    151  1.21.16.1      phil rssadapt_init(struct ieee80211vap *vap)
    152        1.5    dyoung {
    153  1.21.16.1      phil 	struct ieee80211_rssadapt *rs;
    154        1.5    dyoung 
    155  1.21.16.1      phil 	KASSERT(vap->iv_rs == NULL, ("%s: iv_rs already initialized",
    156  1.21.16.1      phil 	    __func__));
    157        1.5    dyoung 
    158  1.21.16.1      phil 	nrefs++;		/* XXX locking */
    159  1.21.16.1      phil 	vap->iv_rs = rs = IEEE80211_MALLOC(sizeof(struct ieee80211_rssadapt),
    160  1.21.16.1      phil 	    M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
    161  1.21.16.1      phil 	if (rs == NULL) {
    162  1.21.16.1      phil 		if_printf(vap->iv_ifp, "couldn't alloc ratectl structure\n");
    163  1.21.16.1      phil 		return;
    164  1.21.16.1      phil 	}
    165  1.21.16.1      phil 	rs->vap = vap;
    166  1.21.16.1      phil 	rssadapt_setinterval(vap, 500 /* msecs */);
    167  1.21.16.1      phil 	rssadapt_sysctlattach(vap, vap->iv_sysctl, vap->iv_oid);
    168        1.5    dyoung }
    169        1.5    dyoung 
    170  1.21.16.1      phil static void
    171  1.21.16.1      phil rssadapt_deinit(struct ieee80211vap *vap)
    172        1.5    dyoung {
    173  1.21.16.1      phil 	IEEE80211_FREE(vap->iv_rs, M_80211_RATECTL);
    174  1.21.16.1      phil 	KASSERT(nrefs > 0, ("imbalanced attach/detach"));
    175  1.21.16.1      phil 	nrefs--;		/* XXX locking */
    176  1.21.16.1      phil }
    177        1.5    dyoung 
    178  1.21.16.1      phil static void
    179  1.21.16.1      phil rssadapt_updatestats(struct ieee80211_rssadapt_node *ra)
    180        1.3    dyoung {
    181  1.21.16.1      phil 	long interval;
    182        1.3    dyoung 
    183  1.21.16.1      phil 	ra->ra_pktrate = (ra->ra_pktrate + 10*(ra->ra_nfail + ra->ra_nok))/2;
    184  1.21.16.1      phil 	ra->ra_nfail = ra->ra_nok = 0;
    185        1.3    dyoung 
    186  1.21.16.1      phil 	/*
    187  1.21.16.1      phil 	 * A node is eligible for its rate to be raised every 1/10 to 10
    188  1.21.16.1      phil 	 * seconds, more eligible in proportion to recent packet rates.
    189  1.21.16.1      phil 	 */
    190  1.21.16.1      phil 	interval = MAX(10*1000, 10*1000 / MAX(1, 10 * ra->ra_pktrate));
    191  1.21.16.1      phil 	ra->ra_raise_interval = msecs_to_ticks(interval);
    192  1.21.16.1      phil }
    193        1.3    dyoung 
    194  1.21.16.1      phil static void
    195  1.21.16.1      phil rssadapt_node_init(struct ieee80211_node *ni)
    196  1.21.16.1      phil {
    197  1.21.16.1      phil 	struct ieee80211_rssadapt_node *ra;
    198  1.21.16.1      phil 	struct ieee80211vap *vap = ni->ni_vap;
    199  1.21.16.1      phil 	struct ieee80211_rssadapt *rsa = vap->iv_rs;
    200  1.21.16.1      phil 	const struct ieee80211_rateset *rs = &ni->ni_rates;
    201  1.21.16.1      phil 
    202  1.21.16.1      phil 	if (ni->ni_rctls == NULL) {
    203  1.21.16.1      phil 		ni->ni_rctls = ra =
    204  1.21.16.1      phil 		    IEEE80211_MALLOC(sizeof(struct ieee80211_rssadapt_node),
    205  1.21.16.1      phil 		        M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
    206  1.21.16.1      phil 		if (ra == NULL) {
    207  1.21.16.1      phil 			if_printf(vap->iv_ifp, "couldn't alloc per-node ratectl "
    208  1.21.16.1      phil 			    "structure\n");
    209  1.21.16.1      phil 			return;
    210        1.3    dyoung 		}
    211        1.3    dyoung 	} else
    212  1.21.16.1      phil 		ra = ni->ni_rctls;
    213  1.21.16.1      phil 	ra->ra_rs = rsa;
    214  1.21.16.1      phil 	ra->ra_rates = *rs;
    215  1.21.16.1      phil 	rssadapt_updatestats(ra);
    216  1.21.16.1      phil 
    217  1.21.16.1      phil 	/* pick initial rate */
    218  1.21.16.1      phil 	for (ra->ra_rix = rs->rs_nrates - 1;
    219  1.21.16.1      phil 	     ra->ra_rix > 0 && (rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL) > 72;
    220  1.21.16.1      phil 	     ra->ra_rix--)
    221  1.21.16.1      phil 		;
    222  1.21.16.1      phil 	ni->ni_txrate = rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL;
    223  1.21.16.1      phil 	ra->ra_ticks = ticks;
    224        1.3    dyoung 
    225  1.21.16.1      phil 	IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
    226  1.21.16.1      phil 	    "RSSADAPT initial rate %d", ni->ni_txrate);
    227        1.3    dyoung }
    228        1.1    dyoung 
    229  1.21.16.1      phil static void
    230  1.21.16.1      phil rssadapt_node_deinit(struct ieee80211_node *ni)
    231        1.1    dyoung {
    232        1.1    dyoung 
    233  1.21.16.1      phil 	IEEE80211_FREE(ni->ni_rctls, M_80211_RATECTL);
    234  1.21.16.1      phil }
    235        1.1    dyoung 
    236  1.21.16.1      phil static __inline int
    237  1.21.16.1      phil bucket(int pktlen)
    238  1.21.16.1      phil {
    239  1.21.16.1      phil 	int i, top, thridx;
    240  1.21.16.1      phil 
    241  1.21.16.1      phil 	for (i = 0, top = IEEE80211_RSSADAPT_BKT0;
    242  1.21.16.1      phil 	     i < IEEE80211_RSSADAPT_BKTS;
    243  1.21.16.1      phil 	     i++, top <<= IEEE80211_RSSADAPT_BKTPOWER) {
    244  1.21.16.1      phil 		thridx = i;
    245  1.21.16.1      phil 		if (pktlen <= top)
    246  1.21.16.1      phil 			break;
    247  1.21.16.1      phil 	}
    248  1.21.16.1      phil 	return thridx;
    249        1.1    dyoung }
    250        1.1    dyoung 
    251  1.21.16.1      phil static int
    252  1.21.16.1      phil rssadapt_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg)
    253        1.1    dyoung {
    254  1.21.16.1      phil 	struct ieee80211_rssadapt_node *ra = ni->ni_rctls;
    255  1.21.16.1      phil 	u_int pktlen = iarg;
    256  1.21.16.1      phil 	const struct ieee80211_rateset *rs = &ra->ra_rates;
    257  1.21.16.1      phil 	uint16_t (*thrs)[IEEE80211_RATE_SIZE];
    258  1.21.16.1      phil 	int rix, rssi;
    259  1.21.16.1      phil 
    260  1.21.16.1      phil 	if ((ticks - ra->ra_ticks) > ra->ra_rs->interval) {
    261  1.21.16.1      phil 		rssadapt_updatestats(ra);
    262  1.21.16.1      phil 		ra->ra_ticks = ticks;
    263  1.21.16.1      phil 	}
    264        1.1    dyoung 
    265  1.21.16.1      phil 	thrs = &ra->ra_rate_thresh[bucket(pktlen)];
    266        1.1    dyoung 
    267  1.21.16.1      phil 	/* XXX this is average rssi, should be using last value */
    268  1.21.16.1      phil 	rssi = ni->ni_ic->ic_node_getrssi(ni);
    269  1.21.16.1      phil 	for (rix = rs->rs_nrates-1; rix >= 0; rix--)
    270  1.21.16.1      phil 		if ((*thrs)[rix] < (rssi << 8))
    271  1.21.16.1      phil 			break;
    272  1.21.16.1      phil 	if (rix != ra->ra_rix) {
    273  1.21.16.1      phil 		/* update public rate */
    274  1.21.16.1      phil 		ni->ni_txrate = ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL;
    275  1.21.16.1      phil 		ra->ra_rix = rix;
    276  1.21.16.1      phil 
    277  1.21.16.1      phil 		IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
    278  1.21.16.1      phil 		    "RSSADAPT new rate %d (pktlen %d rssi %d)",
    279  1.21.16.1      phil 		    ni->ni_txrate, pktlen, rssi);
    280  1.21.16.1      phil 	}
    281  1.21.16.1      phil 	return rix;
    282        1.1    dyoung }
    283        1.1    dyoung 
    284        1.1    dyoung /*
    285        1.1    dyoung  * Adapt the data rate to suit the conditions.  When a transmitted
    286  1.21.16.1      phil  * packet is dropped after RAL_RSSADAPT_RETRY_LIMIT retransmissions,
    287        1.1    dyoung  * raise the RSS threshold for transmitting packets of similar length at
    288        1.1    dyoung  * the same data rate.
    289        1.1    dyoung  */
    290  1.21.16.1      phil static void
    291  1.21.16.1      phil rssadapt_lower_rate(struct ieee80211_rssadapt_node *ra, int pktlen, int rssi)
    292  1.21.16.1      phil {
    293  1.21.16.1      phil 	uint16_t last_thr;
    294  1.21.16.1      phil 	uint16_t (*thrs)[IEEE80211_RATE_SIZE];
    295  1.21.16.1      phil 	u_int rix;
    296  1.21.16.1      phil 
    297  1.21.16.1      phil 	thrs = &ra->ra_rate_thresh[bucket(pktlen)];
    298  1.21.16.1      phil 
    299  1.21.16.1      phil 	rix = ra->ra_rix;
    300  1.21.16.1      phil 	last_thr = (*thrs)[rix];
    301  1.21.16.1      phil 	(*thrs)[rix] = interpolate(master_expavgctl.rc_thresh,
    302  1.21.16.1      phil 	    last_thr, (rssi << 8));
    303  1.21.16.1      phil 
    304  1.21.16.1      phil 	IEEE80211_DPRINTF(ra->ra_rs->vap, IEEE80211_MSG_RATECTL,
    305  1.21.16.1      phil 	    "RSSADAPT lower threshold for rate %d (last_thr %d new thr %d rssi %d)\n",
    306  1.21.16.1      phil 	    ra->ra_rates.rs_rates[rix + 1] & IEEE80211_RATE_VAL,
    307  1.21.16.1      phil 	    last_thr, (*thrs)[rix], rssi);
    308  1.21.16.1      phil }
    309        1.1    dyoung 
    310  1.21.16.1      phil static void
    311  1.21.16.1      phil rssadapt_raise_rate(struct ieee80211_rssadapt_node *ra, int pktlen, int rssi)
    312  1.21.16.1      phil {
    313  1.21.16.1      phil 	uint16_t (*thrs)[IEEE80211_RATE_SIZE];
    314  1.21.16.1      phil 	uint16_t newthr, oldthr;
    315  1.21.16.1      phil 	int rix;
    316  1.21.16.1      phil 
    317  1.21.16.1      phil 	thrs = &ra->ra_rate_thresh[bucket(pktlen)];
    318  1.21.16.1      phil 
    319  1.21.16.1      phil 	rix = ra->ra_rix;
    320  1.21.16.1      phil 	if ((*thrs)[rix + 1] > (*thrs)[rix]) {
    321  1.21.16.1      phil 		oldthr = (*thrs)[rix + 1];
    322  1.21.16.1      phil 		if ((*thrs)[rix] == 0)
    323  1.21.16.1      phil 			newthr = (rssi << 8);
    324  1.21.16.1      phil 		else
    325  1.21.16.1      phil 			newthr = (*thrs)[rix];
    326  1.21.16.1      phil 		(*thrs)[rix + 1] = interpolate(master_expavgctl.rc_decay,
    327  1.21.16.1      phil 		    oldthr, newthr);
    328  1.21.16.1      phil 
    329  1.21.16.1      phil 		IEEE80211_DPRINTF(ra->ra_rs->vap, IEEE80211_MSG_RATECTL,
    330  1.21.16.1      phil 		    "RSSADAPT raise threshold for rate %d (oldthr %d newthr %d rssi %d)\n",
    331  1.21.16.1      phil 		    ra->ra_rates.rs_rates[rix + 1] & IEEE80211_RATE_VAL,
    332  1.21.16.1      phil 		    oldthr, newthr, rssi);
    333        1.1    dyoung 
    334  1.21.16.1      phil 		ra->ra_last_raise = ticks;
    335  1.21.16.1      phil 	}
    336  1.21.16.1      phil }
    337        1.1    dyoung 
    338  1.21.16.1      phil static void
    339  1.21.16.1      phil rssadapt_tx_complete(const struct ieee80211_node *ni,
    340  1.21.16.1      phil     const struct ieee80211_ratectl_tx_status *status)
    341  1.21.16.1      phil {
    342  1.21.16.1      phil 	struct ieee80211_rssadapt_node *ra = ni->ni_rctls;
    343  1.21.16.1      phil 	int pktlen, rssi;
    344        1.1    dyoung 
    345  1.21.16.1      phil 	if ((status->flags &
    346  1.21.16.1      phil 	    (IEEE80211_RATECTL_STATUS_PKTLEN|IEEE80211_RATECTL_STATUS_RSSI)) !=
    347  1.21.16.1      phil 	    (IEEE80211_RATECTL_STATUS_PKTLEN|IEEE80211_RATECTL_STATUS_RSSI))
    348        1.1    dyoung 		return;
    349        1.1    dyoung 
    350  1.21.16.1      phil 	pktlen = status->pktlen;
    351  1.21.16.1      phil 	rssi = status->rssi;
    352  1.21.16.1      phil 
    353  1.21.16.1      phil 	if (status->status == IEEE80211_RATECTL_TX_SUCCESS) {
    354  1.21.16.1      phil 		ra->ra_nok++;
    355  1.21.16.1      phil 		if ((ra->ra_rix + 1) < ra->ra_rates.rs_nrates &&
    356  1.21.16.1      phil 		    (ticks - ra->ra_last_raise) >= ra->ra_raise_interval)
    357  1.21.16.1      phil 			rssadapt_raise_rate(ra, pktlen, rssi);
    358  1.21.16.1      phil 	} else {
    359  1.21.16.1      phil 		ra->ra_nfail++;
    360  1.21.16.1      phil 		rssadapt_lower_rate(ra, pktlen, rssi);
    361        1.1    dyoung 	}
    362  1.21.16.1      phil }
    363        1.1    dyoung 
    364  1.21.16.2      phil #ifdef notyet
    365  1.21.16.1      phil static int
    366  1.21.16.1      phil rssadapt_sysctl_interval(SYSCTL_HANDLER_ARGS)
    367  1.21.16.1      phil {
    368  1.21.16.1      phil 	struct ieee80211vap *vap = arg1;
    369  1.21.16.1      phil 	struct ieee80211_rssadapt *rs = vap->iv_rs;
    370  1.21.16.1      phil 	int msecs = ticks_to_msecs(rs->interval);
    371  1.21.16.1      phil 	int error;
    372        1.1    dyoung 
    373  1.21.16.1      phil 	error = sysctl_handle_int(oidp, &msecs, 0, req);
    374  1.21.16.1      phil 	if (error || !req->newptr)
    375  1.21.16.1      phil 		return error;
    376  1.21.16.1      phil 	rssadapt_setinterval(vap, msecs);
    377  1.21.16.1      phil 	return 0;
    378  1.21.16.1      phil }
    379  1.21.16.2      phil #endif
    380        1.1    dyoung 
    381  1.21.16.1      phil static void
    382  1.21.16.1      phil rssadapt_sysctlattach(struct ieee80211vap *vap,
    383  1.21.16.1      phil     struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
    384  1.21.16.1      phil {
    385  1.21.16.2      phil #ifdef notyet
    386  1.21.16.1      phil 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
    387  1.21.16.1      phil 	    "rssadapt_rate_interval", CTLTYPE_INT | CTLFLAG_RW, vap,
    388  1.21.16.1      phil 	    0, rssadapt_sysctl_interval, "I", "rssadapt operation interval (ms)");
    389  1.21.16.2      phil #endif
    390        1.1    dyoung }
    391