1.\" $OpenBSD: rssadapt.9,v 1.5 2007/06/16 13:17:05 damien Exp $ 2.\" $NetBSD: rssadapt.9,v 1.4 2004/12/08 18:35:56 peter Exp $ 3.\" 4.\" Copyright (c) 2004 David Young. All rights reserved. 5.\" 6.\" This code is by David Young. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above 14.\" copyright notice, this list of conditions and the following 15.\" disclaimer in the documentation and/or other materials 16.\" provided with the distribution. 17.\" 3. The name of David Young may not be used to endorse or promote 18.\" products derived from this software without specific prior 19.\" written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY 22.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 23.\" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24.\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David 25.\" Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 27.\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32.\" POSSIBILITY OF SUCH DAMAGE. 33.\" 34.Dd $Mdocdate: June 16 2007 $ 35.Dt RSSADAPT 9 36.Os 37.Sh NAME 38.Nm rssadapt , 39.Nm ieee80211_rssadapt_choose , 40.Nm ieee80211_rssadapt_input , 41.Nm ieee80211_rssadapt_lower_rate , 42.Nm ieee80211_rssadapt_raise_rate , 43.Nm ieee80211_rssadapt_updatestats 44.Nd rate adaptation based on received signal strength 45.Sh SYNOPSIS 46.In net80211/ieee80211_var.h 47.In net80211/ieee80211_rssadapt.h 48.Ft void 49.Fn ieee80211_rssadapt_input "struct ieee80211com *ic" \ 50"st construct ieee80211_node *ni" "struct ieee80211_rssadapt *ra" "int rssi" 51.Ft void 52.Fn ieee80211_rssadapt_lower_rate "struct ieee80211com *ic" \ 53"const struct ieee80211_node *ni" "struct ieee80211_rssadapt *ra" \ 54"const struct ieee80211_rssdesc *id" 55.Ft void 56.Fn ieee80211_rssadapt_raise_rate "struct ieee80211com *ic" \ 57"struct ieee80211_rssadapt *ra" "const struct ieee80211_rssdesc *id" 58.Ft void 59.Fn ieee80211_rssadapt_updatestats "struct ieee80211_rssadapt *ra" 60.Ft int 61.Fn ieee80211_rssadapt_choose "struct ieee80211_rssadapt *ra" \ 62"const struct ieee80211_rateset *rs" "const struct ieee80211_frame *wh" \ 63"u_int len" "int fixed_rate" "const char *dvname" "int do_not_adapt" 64.Sh DESCRIPTION 65The 66.Nm 67module provides rapid adaptation of transmission data rate to 802.11 68device drivers based on received-signal strength 69.Pq RSS . 70A driver needs only to provide 71.Nm 72with indications of RSS and failure/success of transmissions for 73each 802.11 client or peer. 74For each transmit packet, 75.Nm 76chooses the transmission data rate that offers the best expected 77throughput, given the packet's length and destination. 78.Pp 79.Nm 80models an 802.11 channel very simply 81.Po 82see also the 83.Sx BUGS 84section 85.Pc . 86It assumes that the packet-error rate 87.Pq PER 88is determined by the signal-to-noise ratio 89.Pq S/N 90at the receiver, the transmission data rate, and the packet length. 91The S/N determines the choice of data rate that yields the lowest 92PER for all packets of a certain length. 93.Sh FUNCTIONS 94.Bl -tag -width Ds -compact 95.It Fn ieee80211_rssadapt_choose "ra" "rs" "wh" "len" "fixed_rate" "dvname" \ 96"do_not_adapt" 97.Pp 98Choose the transmission data rate for a packet. 99.Pp 100.Bl -tag -width "do_not_adapt" -compact 101.It Fa ra 102Ordinarily, the 103.Nm 104state object belonging to the node which is the packet destination. 105However, if the destination is a broadcast/multicast address, then 106.Fa ra 107belongs to the BSS node, 108.Va ic-\*(Gtic_bss . 109.It Fa rs 110A list of eligible data rates for the node; for example, the 111rates negotiated when the node associated with the network. 112.It Fa len 113The packet length in bytes, including the 802.11 header and 114frame check sequence 115.Pq FCS . 116.It Fa fixed_rate 117If the operator has set the data rate using, for example, 118.Ic "ifconfig wi0 media ds1" , 119then 120.Fa fixed_rate 121tells the index of that rate in 122.Fa rs . 123.Nm 124obeys a fixed data rate whenever the 802.11 standard allows it: 125sometimes the standard requires multicast/broadcast packets to be 126transmitted at a so-called 127.Dq basic rate . 128.It Fa dvname 129The device driver uses 130.Fa dvname 131to indicate the name of the 132interface for the purpose of diagnostic and debug messages. 133The driver sets 134.Fa dvname 135to 136.Dv NULL 137when no messages are desired. 138.It Fa do_not_adapt 139If 140.Fa do_not_adapt 141is non-zero, then 142.Fn ieee80211_rssadapt_choose 143will choose the highest rate in 144.Fa rs 145that suits the destination, regardless of the RSS. 146.El 147The return value of 148.Fn ieee80211_rssadapt_choose 149is an index into 150.Fa rs , 151indicating its choice of transmit data rate. 152.Pp 153.It Fn ieee80211_rssadapt_input "ic" "ni" "ra" "rssi" 154The RSS serves as a rough estimate of the S/N at each node. 155A driver provides RSS updates using 156.Fn ieee80211_rssadapt_input , 157whose arguments are: 158.Pp 159.Bl -tag -width "rssi" -compact 160.It Fa ic 161The wireless interface's 802.11 state object. 162.It Fa ni 163The 802.11 node whose RSS the driver is updating. 164.It Fa ra 165The node's 166.Nm 167state object. 168.It Fa rssi 169The node's received signal strength indication. 170The range of 171.Fa rssi 172is from 0 to 255. 173.El 174.Pp 175.It Fn ieee80211_rssadapt_lower_rate "ic" "ni" "ra" "id" 176.It Fn ieee80211_rssadapt_raise_rate "ic" "ra" "id" 177Drivers call 178.Fn ieee80211_rssadapt_raise_rate 179and 180.Fn ieee80211_rssadapt_lower_rate 181to indicate transmit successes and failures, respectively. 182.Pp 183.Bl -tag -width Ds -compact 184.It Fa ic 185The 802.11 state object. 186.It Fa ni 187The neighbor to whom the driver transmitted. 188.It Fa ra 189The neighbor's 190.Nm 191state object. 192.It Fa id 193Displays statistics on the transmission attempt. 194.El 195.Pp 196.It Fn ieee80211_rssadapt_updatestats "ra" 197An 802.11 node is eligible for its RSS thresholds to decay every 1981/10 to 10 seconds. 199It is eligible more often (every 1/10 second) at high packet rates, 200and less often (every 10 seconds) at low packet rates. 201A driver assists 202.Nm 203in tracking the exponential-average packet rate by calling 204.Fn ieee80211_rssadapt_updatestats 205every 1/10th second for each node's 206.Vt ieee80211_rssadapt 207object. 208.Pp 209.Bl -tag -width Ds -compact 210.It Fa ra 211The neighbor's 212.Nm 213state object. 214.El 215.El 216.Sh ALGORITHM 217.Nm 218monitors the RSS from neighboring 802.11 nodes, recording the 219exponential average RSS in each neighbor's 220.Vt ieee80211_rssadapt 221structure. 222.Nm 223uses transmit success/failure feedback from the 224device driver to fill a table of RSS thresholds. 225The table is indexed by packet size, 226.Va L , 227and a data rate, 228.Va R , 229to find out the minimum exponential-average RSS that a node must show before 230.Nm 231will indicate that a packet 232.Va L 233bytes long can be transmitted R bits per second with optimal expected 234throughput. 235.Pp 236When the driver indicates a unicast packet is transmitted unsuccessfully 237.Po 238that is, the NIC received no ACK for the packet 239.Pc , 240.Nm 241will move the corresponding RSS threshold toward the exponential 242average RSSI at the time of transmission. 243Thus several consecutive transmit failures for the same 244.Ao 245.Va L , 246.Va R 247.Ac 248tuple will ensure that the RSS threshold rises high enough that 249rate 250.Va R 251is abandoned for packets 252.Va L 253bytes long. 254When the driver indicates a successful transmission, 255the RSS threshold corresponding to the same packet length, but the 256next higher data rate, is lowered slightly. 257The RSS threshold is said to 258.Dq decay . 259This ensures that occasionally 260.Nm 261indicates the driver should try the next higher data rate, 262just in case conditions at the receiver have changed 263.Po 264for example, noise levels have fallen 265.Pc 266and a higher data rate can be supported at the same RSS level. 267.Pp 268The rate of decay is controlled. 269In an interval of 1/10th second 270to 10 seconds, only one RSS threshold per neighbor may decay. 271The interval is connected to the exponential-average rate that packets 272are being transmitted. 273At high packet rates, the interval is shortest. 274It is longest at low packet rates. 275The rationale for this is that RSS thresholds should not decay 276rapidly if there is no information from packet transmissions to 277counteract their decay. 278.Sh DATA STRUCTURES 279An 280.Vt ieee80211_rssdesc 281describes a transmission attempt. 282.Bd -literal -offset indent 283struct ieee80211_rssdesc { 284 u_int id_len; 285 u_int id_rateidx; 286 struct ieee80211_node *id_node; 287 u_int8_t id_rssi; 288}; 289.Ed 290.Pp 291.Fa id_len 292is the length, in bytes, of the transmitted packet. 293.Fa id_node 294points to the neighbor's 295.Vt ieee8021_node , 296and 297.Fa id_rssi 298is the exponential-average RSS at the time the packet was 299transmitted. 300.Fa id_rateidx 301is an index into the destination neighbor's rate-set, 302.Fa id_node-\*(Gtni_rates , 303indicating the transmit data rate for the packet. 304.Pp 305.Vt ieee80211_rssadapt 306contains the rate-adaptation state for a neighboring 802.11 node. 307Ordinarily a driver will 308.Dq subclass 309.Vt ieee80211_node . 310The 311.Vt ieee80211_rssadapt 312structure will be a subclass member. 313In this way, every node's 314.Nm 315condition is independently tracked and stored in its node object. 316.Bd -literal -offset 4n 317struct ieee80211_rssadapt { 318 u_int16_t ra_avg_rssi; 319 u_int32_t ra_nfail; 320 u_int32_t ra_nok; 321 u_int32_t ra_pktrate; 322 u_int16_t ra_rate_thresh[IEEE80211_RSSADAPT_BKTS] 323 [IEEE80211_RATE_SIZE]; 324 struct timeval ra_last_raise; 325 struct timeval ra_raise_interval; 326}; 327.Ed 328.Pp 329.Fa ra_avg_rssi 330is the exponential-average RSS, shifted left 8 bits. 331.Fa ra_nfail 332indicates the number of transmit failures in the current update interval; 333.Fa ra_nok 334the number of transmit successes in the current update interval. 335.Fa ra_pktrate 336indicates the exponential average number of transmit failure/success 337indications over past update intervals. 338This approximates the rate of packet-transmission. 339.Fa ra_rate_thresh 340contains RSS thresholds that are indexed by 341.Aq "packet length, data rate" 342tuples. 343When this node's exponential-average RSS exceeds 344.Fa ra_rate_thresh[i][j] , 345then packets at most 128 x 8^i bytes long are eligible to be 346transmitted at the rate indexed by j. 347.Pp 348.Fa ra_last_raise 349and 350.Fa ra_raise_interval 351are used to control the rate that RSS thresholds 352.Dq decay . 353.Fa ra_last_raise 354indicates when 355.Fn ieee80211_rssadapt_raise_rate 356was last called and 357.Fa ra_raise_interval 358indicates the minimum period between consecutive calls to 359.Fn ieee80211_rssadapt_raise_rate . 360If 361.Fn ieee80211_rssadapt_raise_rate 362is called more than once in any period, the second and subsequent 363calls are ignored. 364.Sh CODE REFERENCES 365This section describes places within the 366.Ox 367source tree where actual code implementing or using 368.Nm 369can be found. 370All pathnames are relative to 371.Pa /usr/src . 372.Pp 373The code for 374.Nm 375is in the file 376.Pa sys/net80211/ieee80211_rssadapt.c . 377.Pp 378.Xr ath 4 379contains a reference implementation. 380See 381.Pa sys/dev/ic/ath.c . 382.Sh SEE ALSO 383.Xr ath 4 , 384.Xr ieee80211 9 385.Rs 386.%A Javier del Prado Pavon 387.%A Sunghyun Choi 388.%T "Link Adaptation Strategy for IEEE 802.11 WLAN via Received Signal \ 389Strength Measurement" 390.%J "ICC'03" 391.%P pp. 1108-1113 392.%C Anchorage, Alaska 393.%D May 2003 394.Re 395.Sh HISTORY 396.Nm 397first appeared in 398.Nx 399and was ported to 400.Ox 401by 402.An Todd C. Miller Aq millert@OpenBSD.org 403.Sh AUTHORS 404.An David Young Aq dyoung@NetBSD.org 405.Sh BUGS 406To cope with interference from microwave ovens, frequency-hopping 407radios, and other sources of RF pulse-trains and bursts, 408.Nm 409should adapt the fragmentation threshold as well as the data rate. 410.Pp 411For improved throughput, 412.Nm 413should indicate to drivers when they should use the 802.11b 414short-preamble. 415.Pp 416The constants in 417.Fn ieee80211_rssadapt_updatestats 418should be configurable. 419