Please note: This project is no longer active. The website is kept online for historic purposes only.
If you´re looking for a Linux driver for your Atheros WLAN device, you should continue here .

Antenna Diversity

Antenna diversity is the term used when the receiver and transmitter use multiple antennas in order to improve the quality of reception/transmission. Many Atheros radios have two antenna connectors which allows you to connect two antennas (NB: MadWifi does not yet support MIMO, the 3+ antenna array devices). Two antennas can be beneficial in a number of scenarios. One typical scenario is called polarization diversity. For example, most laptops have two small dipole antennas oriented differently because as you move around with the laptop one or the other antenna may "line up" better with the access point antenna polarization. There is also spatial diversity which exploits the fact that sometimes two antennas spaced more than a few (~10) wavelengths apart have different reception conditions due to reflections or fading, or other effects.

Receiver diversity

The way receive antenna diversity works is that the radio hardware listens to the begining of the incoming transmission (the preamble stuff) and compares the signal strength on both antennas. It then selects the stronger antenna and receives the body of the packet on that antenna. All this is performed in hardware, the driver can only enable/disable diversity, and if it's disabled it can select which antenna to receive on.

Transmitter Diversity

Transmitter diversity works differently in that the driver needs to tell the radio which antenna to use. In madwifi-old the driver logic was to start transmitting to a station on the default antenna (lowest numbered) and then keep track of the receiving antenna for packets received from that station. If three consecutive packet receptions from a station occur on "the other" antenna then the driver changes the transmit antenna to match the receive antenna. The operation of madwifi-ng is probably the same, but this has not been confirmed.

Apparently the switch that selects which antenna transmits tends to have about a 10dB-15dB attenuation on the non-transmitting antenna. So there is some power that goes to that non-transmitting antenna. Also, if you see fluctuations in output power levels of about that amount on one antenna, then it may be diversity kicking in.

You will definitely want to disable transmitter diversity if you only have one antenna connected. Otherwise 50% of your broadcast and multicast packets (ARP, OSPF) will go out on the wrong antenna. (See r1430, #326, #168.)

Controlling diversity

Antenna diversity can be controlled using sysctl (/proc/sys/dev/wifiX/{diversity,txantenna,rxantenna}):

diversity:
    0: no
    1: yes

txantenna and rxantenna:
    0: auto
    1: antenna 1
    2: antenna 2

Which connector corresponds to antenna 1 and which to antenna 2 depends on the particular radio hardware. For the popular Wistron CM-9 MiniPCI the connector close to the corner of the card is antenna 1, but contrarywise another popular Wistron CM-10 (DCMA-81)MiniPCI (half-size) has connector close to the inside of the card is antena 1 and close to the corner of the card is antenna 2. Do not mix up these CM´s cards!

For example, to disable diversity and select antenna 1 for receive and transmit you'd do the following:

    sysctl -w dev.wifi0.diversity=0
    sysctl -w dev.wifi0.txantenna=1
    sysctl -w dev.wifi0.rxantenna=1 

To save these settings, add them to /etc/sysctl.conf.

If your distribution doesn't include a sysctl.conf file, here's a sh snippet to run from /etc/rc.local:

#!/bin/sh
# sysc_atha.sh
# Usage: sh sysc_atha.sh [tx rx div]
#
t=`cat /proc/sys/dev/wifi0/txantenna`
r=`cat /proc/sys/dev/wifi0/rxantenna`
d=`cat /proc/sys/dev/wifi0/diversity`
t=${1:-$t}
r=${2:-$r}
d=${3:-$d}
(sysctl -w dev.wifi0.txantenna=$t
 sysctl -w dev.wifi0.rxantenna=$r
 sysctl -w dev.wifi0.diversity=$d
)|tr '\n' ' '|sed s/dev.wifi0.//g
echo

e.g.:

sh sysc_atha.sh 2 2 0
txantenna = 2 rxantenna = 2 diversity = 0

What doesn't work

Note that connecting antennas with different coverage areas doesn't really work. When reading about multiple antennas some people think they can connect one high-gain long range antenna for a long distance link and one omnidirectional antenna to serve for local connectivity to a single accesspoint radio. Or one high gain pointing in one direction and a second pointing in a different direction. While this can be made to work in principle, there are a number of problems. The first is that on an accesspoint beacons are only sent out one antenna, so stations on the other antenna are out of luck. The second problem is that when the AP transmits the stations on the other antenna don't hear the transmission and therefore don't do the collision avoidance properly. If you use RTS/CTS then also some stations don't get them at all. The bottom line is that diversity works well when one antenna is a few dB better than the other, which allows higher data rates and fewer packet losses. It does not work well if half the stations only hear one antenna and not at all the other.