Long Distance links with MadWifi
In order to run wireless links over long distances you need to keep a number of things in mind. Foremost you need to think about power and gain: do your radio and antenna combinations result in a sufficient signal-to-noise margin at the receiving ends? After that you need to tune a couple of parameters in the 802.11 protocol to enable proper communication over long distances. Finally, you may want to understand how the links are performing.
For long distance station connections to an AP, please also see eXtendedRangeXR regarding the Atheros XR features.
Power and antenna gain
In order to communicate over longer distances the stock antennas in your laptop and on your access point are unlikely to be sufficient! Some of the options are to purchase higher power radios, to add external bidirection amplifiers, to use high gain antennas, and to do all the above! Note that there is no magic with antennas: in order to get gain you have to get directionality as well. This is pretty obvious if you're looking at dish antennas but it's also the case when looking at high gain omnidirectional antennas! For example, if you buy a 9dBi omni (for operation at 2.4Ghz) you are getting an antenna that is uniform (omni) 360 degrees around, but that has a vertical beamwidth of only about 14 degrees. What this means is that if you mount your antenna vertically, you get 3dB less gain (i.e. only 6dB gain) if you are 7 degrees up or down from horizontal with respect to the antenna. So if you are mounting the antenna in your attic and expect miracles 2 floors down, or if you are dreaming of putting the antenna on that mountain peak next door, think again... (There are onmis with an "electrical downtilt" specifically made for high locations.) For some antenna inspirations take a look at http://www.pacwireless.com/ and http://www.hyperlinktech.com/.
One very handy tool as you are pondering over power and gain is a link analysis calculator. A free one is available at http://www.hol4g.com/rl/TS/hwdt.aspx and will give you a first estimate on how much signal to noise margin you can expect. If you arrive at less than 10dB you shouldn't expect much in terms of bandwidth and count yourself lucky if you can associate at all. You probably need more than 16dB to get into the higher bit rates (say 12Mps and above).
Take a look at UserDocs/AntennaDiversity. You'll want to disable transmit diversity if you only have one antenna connected.
ACK timeout and Slot time
In 802.11a/b/g all data transmissions are acknowledged by the receiving radio and the transmitter makes a number of retransmission attempts if such an ack is not received. (Note that there are ways to send unacknowledged packets using multicast or multimedia features.) The acknowledgments affect long distance links in that the transmitter waits for a limited amount of time before retrying. If the ACK timeout is set too short, the transmitter will start retransmitting before an ACK could have possibly been received and this retransmission may well actually interfere with an ACK that is "on it's way".(It is important to note that this retransmission will occur after a random backoff) The end result is that actual throughput is very low and the number of retransmissions is excessively high. If, conversely, the ACK timeout is set too long, the transmitter waits unncesessarily long before retransmitting in the case no ACK is received. This represents lost time and thus reduces the throughput of the link.
In addition to the ACK timeout, there are a number of other time constants that need to be adjusted for long distance links. These time constants have to do with the collision sensing and avoidance parts of the protocol.
The bottom line is that you need to determine the distance between the radios (or the maximum distance in the case of a mobile installation), calculate the time of flight of the packets in microseconds, and then set the ACK timeout to a little more than a round-trip time as the CTS timeout as well as the Slot time to the one-way time. These settings are available in /proc/sys/dev/wifiX as slottime, ctstimeout, and acktimeout. The easiest way to change these settings is using the athctrl utility provided with the driver. For example, athctrl -d 15000 sets these parameters appropriately for stations located 15000 meters apart (approx 9.4 miles). Note that it is important that all stations that are communicating with each other use the same value. So if you have an access point in a point-to-multipoint set-up where one client is 10000 meters away and the other is 15000 meters away then you should run athctrl -d 15000 on all three nodes.
One little problem with the slot time is that 802.11g requires it to be switched between 9us and 20us depending on whether a 802.11b client is associated or not (or something like that). You will thus see the slot time suddenly be reset to one of these values if any association operation takes place on your access point. There is a patch in the works to lock the slot time to what you set it. This description will be updated when that goes into the code base...
Performance expectations and measurements
The first measurement you are likely to do is to look at the SNR (signal to noise ratio) or quality values displayed by iwconfig, iwlist, and athstats. What the values mean depends on the driver and differs from chipset to chipset. For MadWifi there is only a single value that means anything and that's the signal-to-noise or quality value. This value is in dB above the noise floor. That means the SNR or quality or rssi values reported by the various applications are all derived from so-called rssi (received signal strength indication) values placed into the tx/rx descriptors by the chipset and retrieved by the driver.
How about the signal strength and noise floor values you may see? Well, the hardware only returns rssi/SNR measurements and the driver simply sets the noise floor value returned to various tools to a constant -95dB. From that some tools calculate signal strength to be noise floor + signal to noise. So, in other words, if you are using MadWifi you may as well only look at SNR and ignore all other values as they don't contain any additional information. Comments in the driver further explain: "If you assume that the noise floor is -95, which is an excellent assumption 99.5 % of the time, then you can derive the absolute signal level (i.e. -95 + rssi). There are some other slight factors to take into account depending on whether the rssi measurement is from 11b, 11g, or 11a. These differences are at most 2db and can be documented."
The athctrl tool
As mentioned in the ACK timeout and Slottime section, athctrl tool is the primary method for tweaking the link distance related settings on the Atheros radios. It will adjust the CTS and ACK timeout values based upon the distance between your links.
The following example sets first Atheros radio to a distance of 22531 meters or 14 miles. Please notice the differences in usage for athctrl between MadWifi and MadWifi-Old due to the old interface naming scheme.
athctrl -i wifi0 -d 22531
For MadWifi-Old:athctrl -i ath0 -d 22531
Note: The formula used for the calculation of the tuned parameters is not fully correct. It might be that you have to give a slightly different (larger or shorter) distance in order to get optimal results.
FCC power limits
Power in 2.4GHz band is limited to 4W EIRP. There are 13 channels; see http://www.melbpc.org.au/pcupdate/2404/2404article6.htm
Power is limited to 100mw p.i.r.e with the antenna given with your hardware.
Your network is limited to 300m.
You have to buy a licence to IBPT if you want more: 850 Euro for a private network (only once) You have to declare to the IBPT what hardware you use. You also have to notice them when you change or add hardware.
http://www.comunicazioni.it/it/index.php?IdPag=699 (in Italian)
http://www.comunicazioni.it/it/index.php?IdPag=1039 (in Italian)
http://www.bakom.admin.ch/themen/technologie/01223/ (2.4 and 5 GHz bands; in multiple languages)
http://www.cofetel.gob.mx (In Spanish)