Home | History | Annotate | Line # | Download | only in net80211
ieee80211_rssadapt.c revision 1.21.16.4
      1  1.21.16.4      phil /*	$NetBSD: ieee80211_rssadapt.c,v 1.21.16.4 2018/07/20 20:33:05 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.4      phil #ifdef notyet
    111  1.21.16.1      phil static void	rssadapt_sysctlattach(struct ieee80211vap *,
    112  1.21.16.1      phil 			struct sysctl_ctx_list *, struct sysctl_oid *);
    113  1.21.16.4      phil #endif
    114  1.21.16.1      phil 
    115  1.21.16.1      phil /* number of references from net80211 layer */
    116  1.21.16.1      phil static	int nrefs = 0;
    117  1.21.16.1      phil 
    118  1.21.16.3      phil #if __FreeBSD__
    119  1.21.16.3      phil static const struct ieee80211_ratectl rssadapt = {
    120  1.21.16.3      phil #elif __NetBSD__
    121  1.21.16.3      phil const struct ieee80211_ratectl ratectl_rssadapt = {
    122  1.21.16.3      phil #endif
    123  1.21.16.1      phil 	.ir_name	= "rssadapt",
    124  1.21.16.1      phil 	.ir_attach	= NULL,
    125  1.21.16.1      phil 	.ir_detach	= NULL,
    126  1.21.16.1      phil 	.ir_init	= rssadapt_init,
    127  1.21.16.1      phil 	.ir_deinit	= rssadapt_deinit,
    128  1.21.16.1      phil 	.ir_node_init	= rssadapt_node_init,
    129  1.21.16.1      phil 	.ir_node_deinit	= rssadapt_node_deinit,
    130  1.21.16.1      phil 	.ir_rate	= rssadapt_rate,
    131  1.21.16.1      phil 	.ir_tx_complete	= rssadapt_tx_complete,
    132  1.21.16.1      phil 	.ir_tx_update	= NULL,
    133  1.21.16.1      phil 	.ir_setinterval	= rssadapt_setinterval,
    134  1.21.16.1      phil };
    135  1.21.16.3      phil #if __FreeBSD__
    136  1.21.16.1      phil IEEE80211_RATECTL_MODULE(rssadapt, 1);
    137  1.21.16.1      phil IEEE80211_RATECTL_ALG(rssadapt, IEEE80211_RATECTL_RSSADAPT, rssadapt);
    138  1.21.16.3      phil #endif
    139        1.5    dyoung 
    140  1.21.16.1      phil static void
    141  1.21.16.1      phil rssadapt_setinterval(const struct ieee80211vap *vap, int msecs)
    142  1.21.16.1      phil {
    143  1.21.16.1      phil 	struct ieee80211_rssadapt *rs = vap->iv_rs;
    144  1.21.16.1      phil 	int t;
    145        1.5    dyoung 
    146  1.21.16.1      phil 	if (msecs < 100)
    147  1.21.16.1      phil 		msecs = 100;
    148  1.21.16.1      phil 	t = msecs_to_ticks(msecs);
    149  1.21.16.1      phil 	rs->interval = (t < 1) ? 1 : t;
    150        1.5    dyoung }
    151        1.5    dyoung 
    152  1.21.16.1      phil static void
    153  1.21.16.1      phil rssadapt_init(struct ieee80211vap *vap)
    154        1.5    dyoung {
    155  1.21.16.1      phil 	struct ieee80211_rssadapt *rs;
    156        1.5    dyoung 
    157  1.21.16.1      phil 	KASSERT(vap->iv_rs == NULL, ("%s: iv_rs already initialized",
    158  1.21.16.1      phil 	    __func__));
    159        1.5    dyoung 
    160  1.21.16.1      phil 	nrefs++;		/* XXX locking */
    161  1.21.16.1      phil 	vap->iv_rs = rs = IEEE80211_MALLOC(sizeof(struct ieee80211_rssadapt),
    162  1.21.16.1      phil 	    M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
    163  1.21.16.1      phil 	if (rs == NULL) {
    164  1.21.16.1      phil 		if_printf(vap->iv_ifp, "couldn't alloc ratectl structure\n");
    165  1.21.16.1      phil 		return;
    166  1.21.16.1      phil 	}
    167  1.21.16.1      phil 	rs->vap = vap;
    168  1.21.16.1      phil 	rssadapt_setinterval(vap, 500 /* msecs */);
    169  1.21.16.4      phil #ifdef notyet
    170  1.21.16.1      phil 	rssadapt_sysctlattach(vap, vap->iv_sysctl, vap->iv_oid);
    171  1.21.16.4      phil #endif
    172        1.5    dyoung }
    173        1.5    dyoung 
    174  1.21.16.1      phil static void
    175  1.21.16.1      phil rssadapt_deinit(struct ieee80211vap *vap)
    176        1.5    dyoung {
    177  1.21.16.1      phil 	IEEE80211_FREE(vap->iv_rs, M_80211_RATECTL);
    178  1.21.16.1      phil 	KASSERT(nrefs > 0, ("imbalanced attach/detach"));
    179  1.21.16.1      phil 	nrefs--;		/* XXX locking */
    180  1.21.16.1      phil }
    181        1.5    dyoung 
    182  1.21.16.1      phil static void
    183  1.21.16.1      phil rssadapt_updatestats(struct ieee80211_rssadapt_node *ra)
    184        1.3    dyoung {
    185  1.21.16.1      phil 	long interval;
    186        1.3    dyoung 
    187  1.21.16.1      phil 	ra->ra_pktrate = (ra->ra_pktrate + 10*(ra->ra_nfail + ra->ra_nok))/2;
    188  1.21.16.1      phil 	ra->ra_nfail = ra->ra_nok = 0;
    189        1.3    dyoung 
    190  1.21.16.1      phil 	/*
    191  1.21.16.1      phil 	 * A node is eligible for its rate to be raised every 1/10 to 10
    192  1.21.16.1      phil 	 * seconds, more eligible in proportion to recent packet rates.
    193  1.21.16.1      phil 	 */
    194  1.21.16.1      phil 	interval = MAX(10*1000, 10*1000 / MAX(1, 10 * ra->ra_pktrate));
    195  1.21.16.1      phil 	ra->ra_raise_interval = msecs_to_ticks(interval);
    196  1.21.16.1      phil }
    197        1.3    dyoung 
    198  1.21.16.1      phil static void
    199  1.21.16.1      phil rssadapt_node_init(struct ieee80211_node *ni)
    200  1.21.16.1      phil {
    201  1.21.16.1      phil 	struct ieee80211_rssadapt_node *ra;
    202  1.21.16.1      phil 	struct ieee80211vap *vap = ni->ni_vap;
    203  1.21.16.1      phil 	struct ieee80211_rssadapt *rsa = vap->iv_rs;
    204  1.21.16.1      phil 	const struct ieee80211_rateset *rs = &ni->ni_rates;
    205  1.21.16.1      phil 
    206  1.21.16.1      phil 	if (ni->ni_rctls == NULL) {
    207  1.21.16.1      phil 		ni->ni_rctls = ra =
    208  1.21.16.1      phil 		    IEEE80211_MALLOC(sizeof(struct ieee80211_rssadapt_node),
    209  1.21.16.1      phil 		        M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
    210  1.21.16.1      phil 		if (ra == NULL) {
    211  1.21.16.1      phil 			if_printf(vap->iv_ifp, "couldn't alloc per-node ratectl "
    212  1.21.16.1      phil 			    "structure\n");
    213  1.21.16.1      phil 			return;
    214        1.3    dyoung 		}
    215        1.3    dyoung 	} else
    216  1.21.16.1      phil 		ra = ni->ni_rctls;
    217  1.21.16.1      phil 	ra->ra_rs = rsa;
    218  1.21.16.1      phil 	ra->ra_rates = *rs;
    219  1.21.16.1      phil 	rssadapt_updatestats(ra);
    220  1.21.16.1      phil 
    221  1.21.16.1      phil 	/* pick initial rate */
    222  1.21.16.1      phil 	for (ra->ra_rix = rs->rs_nrates - 1;
    223  1.21.16.1      phil 	     ra->ra_rix > 0 && (rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL) > 72;
    224  1.21.16.1      phil 	     ra->ra_rix--)
    225  1.21.16.1      phil 		;
    226  1.21.16.1      phil 	ni->ni_txrate = rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL;
    227  1.21.16.1      phil 	ra->ra_ticks = ticks;
    228        1.3    dyoung 
    229  1.21.16.1      phil 	IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
    230  1.21.16.1      phil 	    "RSSADAPT initial rate %d", ni->ni_txrate);
    231        1.3    dyoung }
    232        1.1    dyoung 
    233  1.21.16.1      phil static void
    234  1.21.16.1      phil rssadapt_node_deinit(struct ieee80211_node *ni)
    235        1.1    dyoung {
    236        1.1    dyoung 
    237  1.21.16.1      phil 	IEEE80211_FREE(ni->ni_rctls, M_80211_RATECTL);
    238  1.21.16.1      phil }
    239        1.1    dyoung 
    240  1.21.16.1      phil static __inline int
    241  1.21.16.1      phil bucket(int pktlen)
    242  1.21.16.1      phil {
    243  1.21.16.1      phil 	int i, top, thridx;
    244  1.21.16.1      phil 
    245  1.21.16.1      phil 	for (i = 0, top = IEEE80211_RSSADAPT_BKT0;
    246  1.21.16.1      phil 	     i < IEEE80211_RSSADAPT_BKTS;
    247  1.21.16.1      phil 	     i++, top <<= IEEE80211_RSSADAPT_BKTPOWER) {
    248  1.21.16.1      phil 		thridx = i;
    249  1.21.16.1      phil 		if (pktlen <= top)
    250  1.21.16.1      phil 			break;
    251  1.21.16.1      phil 	}
    252  1.21.16.1      phil 	return thridx;
    253        1.1    dyoung }
    254        1.1    dyoung 
    255  1.21.16.1      phil static int
    256  1.21.16.1      phil rssadapt_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg)
    257        1.1    dyoung {
    258  1.21.16.1      phil 	struct ieee80211_rssadapt_node *ra = ni->ni_rctls;
    259  1.21.16.1      phil 	u_int pktlen = iarg;
    260  1.21.16.1      phil 	const struct ieee80211_rateset *rs = &ra->ra_rates;
    261  1.21.16.1      phil 	uint16_t (*thrs)[IEEE80211_RATE_SIZE];
    262  1.21.16.1      phil 	int rix, rssi;
    263  1.21.16.1      phil 
    264  1.21.16.1      phil 	if ((ticks - ra->ra_ticks) > ra->ra_rs->interval) {
    265  1.21.16.1      phil 		rssadapt_updatestats(ra);
    266  1.21.16.1      phil 		ra->ra_ticks = ticks;
    267  1.21.16.1      phil 	}
    268        1.1    dyoung 
    269  1.21.16.1      phil 	thrs = &ra->ra_rate_thresh[bucket(pktlen)];
    270        1.1    dyoung 
    271  1.21.16.1      phil 	/* XXX this is average rssi, should be using last value */
    272  1.21.16.1      phil 	rssi = ni->ni_ic->ic_node_getrssi(ni);
    273  1.21.16.1      phil 	for (rix = rs->rs_nrates-1; rix >= 0; rix--)
    274  1.21.16.1      phil 		if ((*thrs)[rix] < (rssi << 8))
    275  1.21.16.1      phil 			break;
    276  1.21.16.1      phil 	if (rix != ra->ra_rix) {
    277  1.21.16.1      phil 		/* update public rate */
    278  1.21.16.1      phil 		ni->ni_txrate = ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL;
    279  1.21.16.1      phil 		ra->ra_rix = rix;
    280  1.21.16.1      phil 
    281  1.21.16.1      phil 		IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
    282  1.21.16.1      phil 		    "RSSADAPT new rate %d (pktlen %d rssi %d)",
    283  1.21.16.1      phil 		    ni->ni_txrate, pktlen, rssi);
    284  1.21.16.1      phil 	}
    285  1.21.16.1      phil 	return rix;
    286        1.1    dyoung }
    287        1.1    dyoung 
    288        1.1    dyoung /*
    289        1.1    dyoung  * Adapt the data rate to suit the conditions.  When a transmitted
    290  1.21.16.1      phil  * packet is dropped after RAL_RSSADAPT_RETRY_LIMIT retransmissions,
    291        1.1    dyoung  * raise the RSS threshold for transmitting packets of similar length at
    292        1.1    dyoung  * the same data rate.
    293        1.1    dyoung  */
    294  1.21.16.1      phil static void
    295  1.21.16.1      phil rssadapt_lower_rate(struct ieee80211_rssadapt_node *ra, int pktlen, int rssi)
    296  1.21.16.1      phil {
    297  1.21.16.1      phil 	uint16_t last_thr;
    298  1.21.16.1      phil 	uint16_t (*thrs)[IEEE80211_RATE_SIZE];
    299  1.21.16.1      phil 	u_int rix;
    300  1.21.16.1      phil 
    301  1.21.16.1      phil 	thrs = &ra->ra_rate_thresh[bucket(pktlen)];
    302  1.21.16.1      phil 
    303  1.21.16.1      phil 	rix = ra->ra_rix;
    304  1.21.16.1      phil 	last_thr = (*thrs)[rix];
    305  1.21.16.1      phil 	(*thrs)[rix] = interpolate(master_expavgctl.rc_thresh,
    306  1.21.16.1      phil 	    last_thr, (rssi << 8));
    307  1.21.16.1      phil 
    308  1.21.16.1      phil 	IEEE80211_DPRINTF(ra->ra_rs->vap, IEEE80211_MSG_RATECTL,
    309  1.21.16.1      phil 	    "RSSADAPT lower threshold for rate %d (last_thr %d new thr %d rssi %d)\n",
    310  1.21.16.1      phil 	    ra->ra_rates.rs_rates[rix + 1] & IEEE80211_RATE_VAL,
    311  1.21.16.1      phil 	    last_thr, (*thrs)[rix], rssi);
    312  1.21.16.1      phil }
    313        1.1    dyoung 
    314  1.21.16.1      phil static void
    315  1.21.16.1      phil rssadapt_raise_rate(struct ieee80211_rssadapt_node *ra, int pktlen, int rssi)
    316  1.21.16.1      phil {
    317  1.21.16.1      phil 	uint16_t (*thrs)[IEEE80211_RATE_SIZE];
    318  1.21.16.1      phil 	uint16_t newthr, oldthr;
    319  1.21.16.1      phil 	int rix;
    320  1.21.16.1      phil 
    321  1.21.16.1      phil 	thrs = &ra->ra_rate_thresh[bucket(pktlen)];
    322  1.21.16.1      phil 
    323  1.21.16.1      phil 	rix = ra->ra_rix;
    324  1.21.16.1      phil 	if ((*thrs)[rix + 1] > (*thrs)[rix]) {
    325  1.21.16.1      phil 		oldthr = (*thrs)[rix + 1];
    326  1.21.16.1      phil 		if ((*thrs)[rix] == 0)
    327  1.21.16.1      phil 			newthr = (rssi << 8);
    328  1.21.16.1      phil 		else
    329  1.21.16.1      phil 			newthr = (*thrs)[rix];
    330  1.21.16.1      phil 		(*thrs)[rix + 1] = interpolate(master_expavgctl.rc_decay,
    331  1.21.16.1      phil 		    oldthr, newthr);
    332  1.21.16.1      phil 
    333  1.21.16.1      phil 		IEEE80211_DPRINTF(ra->ra_rs->vap, IEEE80211_MSG_RATECTL,
    334  1.21.16.1      phil 		    "RSSADAPT raise threshold for rate %d (oldthr %d newthr %d rssi %d)\n",
    335  1.21.16.1      phil 		    ra->ra_rates.rs_rates[rix + 1] & IEEE80211_RATE_VAL,
    336  1.21.16.1      phil 		    oldthr, newthr, rssi);
    337        1.1    dyoung 
    338  1.21.16.1      phil 		ra->ra_last_raise = ticks;
    339  1.21.16.1      phil 	}
    340  1.21.16.1      phil }
    341        1.1    dyoung 
    342  1.21.16.1      phil static void
    343  1.21.16.1      phil rssadapt_tx_complete(const struct ieee80211_node *ni,
    344  1.21.16.1      phil     const struct ieee80211_ratectl_tx_status *status)
    345  1.21.16.1      phil {
    346  1.21.16.1      phil 	struct ieee80211_rssadapt_node *ra = ni->ni_rctls;
    347  1.21.16.1      phil 	int pktlen, rssi;
    348        1.1    dyoung 
    349  1.21.16.1      phil 	if ((status->flags &
    350  1.21.16.1      phil 	    (IEEE80211_RATECTL_STATUS_PKTLEN|IEEE80211_RATECTL_STATUS_RSSI)) !=
    351  1.21.16.1      phil 	    (IEEE80211_RATECTL_STATUS_PKTLEN|IEEE80211_RATECTL_STATUS_RSSI))
    352        1.1    dyoung 		return;
    353        1.1    dyoung 
    354  1.21.16.1      phil 	pktlen = status->pktlen;
    355  1.21.16.1      phil 	rssi = status->rssi;
    356  1.21.16.1      phil 
    357  1.21.16.1      phil 	if (status->status == IEEE80211_RATECTL_TX_SUCCESS) {
    358  1.21.16.1      phil 		ra->ra_nok++;
    359  1.21.16.1      phil 		if ((ra->ra_rix + 1) < ra->ra_rates.rs_nrates &&
    360  1.21.16.1      phil 		    (ticks - ra->ra_last_raise) >= ra->ra_raise_interval)
    361  1.21.16.1      phil 			rssadapt_raise_rate(ra, pktlen, rssi);
    362  1.21.16.1      phil 	} else {
    363  1.21.16.1      phil 		ra->ra_nfail++;
    364  1.21.16.1      phil 		rssadapt_lower_rate(ra, pktlen, rssi);
    365        1.1    dyoung 	}
    366  1.21.16.1      phil }
    367        1.1    dyoung 
    368  1.21.16.2      phil #ifdef notyet
    369  1.21.16.1      phil static int
    370  1.21.16.1      phil rssadapt_sysctl_interval(SYSCTL_HANDLER_ARGS)
    371  1.21.16.1      phil {
    372  1.21.16.1      phil 	struct ieee80211vap *vap = arg1;
    373  1.21.16.1      phil 	struct ieee80211_rssadapt *rs = vap->iv_rs;
    374  1.21.16.1      phil 	int msecs = ticks_to_msecs(rs->interval);
    375  1.21.16.1      phil 	int error;
    376        1.1    dyoung 
    377  1.21.16.1      phil 	error = sysctl_handle_int(oidp, &msecs, 0, req);
    378  1.21.16.1      phil 	if (error || !req->newptr)
    379  1.21.16.1      phil 		return error;
    380  1.21.16.1      phil 	rssadapt_setinterval(vap, msecs);
    381  1.21.16.1      phil 	return 0;
    382  1.21.16.1      phil }
    383        1.1    dyoung 
    384  1.21.16.1      phil static void
    385  1.21.16.1      phil rssadapt_sysctlattach(struct ieee80211vap *vap,
    386  1.21.16.1      phil     struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
    387  1.21.16.1      phil {
    388  1.21.16.1      phil 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
    389  1.21.16.1      phil 	    "rssadapt_rate_interval", CTLTYPE_INT | CTLFLAG_RW, vap,
    390  1.21.16.1      phil 	    0, rssadapt_sysctl_interval, "I", "rssadapt operation interval (ms)");
    391        1.1    dyoung }
    392  1.21.16.4      phil #endif
    393