
Introduction
I think I won’t be mistaken if most of us have an Internet connection as follows: there is some rather high-speed wired channel to the apartment (now gigabit is not uncommon), and in the apartment it is met by a router that distributes this Internet to customers “Black” ip and address translation.
Quite often a strange situation is observed: with a high-speed wire, a very narrow wifi-channel is distributed from the router, which does not load even half of the wire. At the same time, although formally Wi-Fi, especially in its ac version, supports some huge speeds, when checking it turns out that either Wi-Fi is connected at a lower speed, or it is connected, but does not show speed in practice, or it loses packets, either all together.
')
At some point, and I ran into a similar problem, and decided to configure my Wi-Fi humanly. Surprisingly, it took about 40 times longer than I expected. In addition, somehow it happened that all the instructions for setting up Wi-Fi, which I found, converged to one of two types: the first one offered to put the router higher and straighten the antenna, for reading the second I did not have an honest understanding of spatial multiplexing algorithms .
Actually, this note is an attempt to fill in the gap in the instructions. I will immediately say that the task is not fully resolved, despite decent progress, the stability of the connection could still be better, so I would be glad to hear the comments of colleagues on the topics described.
Chapter 1:
So, setting the problemThe Wifi router offered by the provider ceased to cope with its duties: there are long (30 seconds and more) periods when the ping to the access point fails, there are very long (about an hour) periods when the ping to the access point reaches 3500 ms, there are long periods when the connection speed with the access point does not exceed 200 kbps.
Scanning the range using windows-utility inSSIDer produces a picture presented at the beginning of the article. The district has 44 Wifi SSID in the 2.4 GHz band and one network in the 5.2 GHz band.
Solution ToolsSelf-assembled computer Celeron 430, 2b Ram, SSD, fanless, two wireless network cards on the chip Ralink rt2800pci, Slackware Linux 14.2, Hostapd from Git in September 2016.
Assembling the router is beyond the scope of this note, although I note that the Celeron 430 has shown itself well in fanless mode. I note that the current configuration is the last, but not final. Perhaps improvements are still feasible.
DecisionIn fact, the solution should, for good, be to run hostapd with minimal changes to the settings. However, the experience so well confirmed the truth of the saying "it was smooth on paper, but forgot about the ravines" that it took the writing of this article to systematize knowledge about all the unclear details. Also, I initially would like to avoid low-level details for the harmony of presentation, but it turned out that this is impossible.
Chapter 2
Some theoryFrequencies
Wi-Fi is a wireless standard. From the point of view of OSI L2, the access point implements a switch type hub, but most often it is also combined with a router-level OSI L3 switch, which leads to a fair amount of confusion.
We will be most interested in the OSI L1 level, that is, in fact, the environment in which the packets run.
Wi-Fi is a radio system. As you know, the radio system consists of a receiver and a transmitter. In Wi-Fi, the access point and client device perform both roles in turn.
The Wi-Fi transmitter operates at a certain frequency. These frequencies are numbered, and each number corresponds to a certain frequency. Important: Despite the fact that for any integer there is a theoretical correspondence to this number of a certain frequency, Wi-Fi can work only in limited frequency ranges (there are three, 2.4 GHz, 5.2 GHz, 5.7 GHz), and only on some of the numbers.
A complete list of matches can be viewed in Wikipedia, it’s important for us that when setting up an access point, you need to specify on which channel the carrier frequency of our signal will be located.
Unobvious detail: not all Wi-Fi standards support all frequencies.
There are two Wi-Fi standards: a and b. “A” is older and operates in the 5 GHz band, “b” is newer and operates in the 2.4 GHz band. In this case, b is slower (11 mbit instead of 54 mbit, that is, 1.2 megabytes per second instead of 7 megabytes per second), and the 2.4 GHz band already accommodates fewer stations. Why so - a mystery. It is doubly mysterious why there is practically no access point for a standard in nature.

(Picture taken from Wikipedia.)

(Actually, I'm a little cunning, because a supports the frequency range of 3.7 GHz. However, I have never seen a single device that knows anything about this range.)
Wait, you ask, but there are also 802.11g, n, ac - standards, and they, it seems, just have to beat on speed unhappy a and b.
But no, I will answer you. The g standard is a belated attempt to bring the speed b to the speed a, in the 2.4 GHz band. But why, you answer me, did you even remember about b? The answer is, because despite the fact that the ranges of both b and g are called 2.4, in fact they are slightly different, and the range of b is one channel longer.
Standards n and ac have nothing to do with ranges at all - they regulate speed, and nothing more. The standard n point can be either “in the base” a (and operate at 5 GHz), or “in the base” b and operate at 2.4 GHz. I don’t know about the ac standard point because I didn’t see it.
That is, when you buy an access point n, you need to look very carefully at which ranges this n works.
It is important that at one point in time one Wi-Fi chip can work only in one range. If your access point claims that it can work in two at the same time, such as free routers from popular providers of Virgin or British Telecom, it means that there are actually two chips in it.
Channel width
In fact, I have to apologize, because I said earlier that a certain range is longer than another, without explaining what “longer” is. Generally speaking, not only the carrier frequency is important for signal transmission, but also the width of the encoded stream. The width is what frequencies above and below the carrier the existing signal can climb. Usually (and fortunately, in Wi-Fi), the channels are symmetrical, centered on the carrier.
So in Wi-Fi channels can be 10, 20, 22, 40, 80 and 160 MHz wide. At the same time, I have never seen access points with a channel width of 10 MHz.
So, one of the most amazing properties of Wi-Fi is that despite the fact that the channels are numbered, they intersect. And not only with neighbors, but also with channels through 3 from myself. In other words, in the 2.4 GHz band, only access points operating on channels 1, 6, and 11 are not intersected by streams of 20 MHz wide. In other words, only three access points can work side by side so as not to interfere with each other.
What is an access point with a 40 MHz channel? The answer is an access point that occupies two channels (non-overlapping).
The question is: how many 80 and 160 MHz channels fit in the 2.4 GHz band?
Answer: None.
The question is, what does the channel width affect? I do not know the exact answer to this question, I could not verify it.
I know that if the network intersects with other networks, the stability of the connection will be worse. A channel width of 40 MHz gives more intersections and a worse connection. According to the standard, if there are other access points operating around the point, the 40 MHz mode should not be activated.
Is it true that double the width of the channel twice gives greater bandwidth?
It seems to be, yes, but it is impossible to verify.
Question: If there are three antennas on my access point, is it true that it can create three spatial streams and triple the connection speed?
The answer is: unknown. It may happen that of the three antennas, two can only deal with sending, but not receiving packets. And the speed of the signal will be unbalanced.
Question: So how many megabits does one antenna give?
Answer: You can see here
en.wikipedia.org/wiki/IEEE_802.11n-2009#Data_ratesThe list is weird and nonlinear.
Obviously, the most important parameter is the MCS index, which determines the speed.
Question: Where do such strange speeds come from?
Answer: There is such a thing as HT Capabilities. These are optional chips that can slightly change the signal. Fishechki are very useful: SHORT-GI adds a bit of speed, about 20 Mbps, LDPC, RX STBC, TX STBC add stability (that is, they must reduce ping and packet loss). However, your hardware can easily not support them and at the same time be quite “honest” 802.11n.
Signal strength
The easiest way to deal with bad communication is to roast more power into the transmitter. In Wi-Fi transmission power can be up to 30 dBm.
Chapter 3
The solution of the problemFrom all of the above listed vinaigrette, it would seem, we can draw the following conclusion: the Wi-Fi can implement two “modes” of functioning. "Improving speed" and "improving quality."
The first one, it would seem, should say: take the most unoccupied channel, 40 MHz channel width, more antennas (preferably 4), and add more Capabilities.
Second, remove everything except the basic n-mode, turn on the power more, and turn on those Capabilities that add stability.
Recalling the proverb about the ravines, let us describe what exactly the irregularities of the area are waiting for us when trying to implement plans 1 and 2.
Ravine zero
Although Ralink rt2x00 chipsets are the most popular chipsets with support for the n standard and are found in both high price cards (Cisco) and low end (TRENDNET), and moreover, they look completely different in lspci, they may have radically different functionality, in particular, only support the 2.4 band, only the 5 GHz band, or support the incomprehensible than the limited parts of both bands. What is the difference - a mystery. It is also a mystery why a card with three antennas only supports Rx STBC in two streams. And why both of them do not support LDPC.
The first ravine
In the 2.4 range, there are only three non-overlapping channels. We have already spoken on this subject and I will not repeat it.
Second ravine
Not all channels allow you to increase the channel width up to 40 MHz, moreover, how wide a channel the card will agree on depends on the card chipset, card manufacturer, processor load and weather on Mars.
The third and largest gully
Regulatory domainIf you didn’t have enough happiness for the fact that the Wi-Fi standards themselves are a noble salad, then rejoice that every country in the world seeks to restrict and limit Wi-Fi in various ways. We are still not so bad in the UK, unlike, say, the United States, where the Wi-Fi spectrum is over-regulated.
So, the regulatory domain may require restrictions on transmitter power, the ability to launch an access point on a channel, the permissible modulation technologies on a channel, and also require some spectrum pacification technologies, such as
DFS (dynamic frequency selection), radar detection (which yet each regdomain has its own, say, in the Americas almost everywhere proposed by the FCC, in Europe it is different, ETSI), or auto-bw (I do not know what it is). At the same time with many of them the access point does not start.
Many regulatory domains simply ban some frequencies in principle.
You can set the regulatory domain with the command:
iw reg set NAME
The regulatory domain can not be set, but then the system will be guided by combining all the restrictions, that is, the worst option possible.
Fortunately, firstly, data on regulatory domains is publicly available on the kernel site:
git.kernel.org/cgit/linux/kernel/git/sforshee/wireless-regdb.git/tree/db.txtAnd you can search for them. In principle, you can probably patch the kernel so that it ignores the regulatory domain, but it is necessary to recompile the kernel or at least the regulatory daemon crda.
Fortunately, the
iw phy info
displays all the capabilities of our device, taking into account (!) The regulatory domain.
So, how do we fix the state of our Wi-Fi?To begin with, we will find a country in which channel 13 is not prohibited. The path at least half the frequency will be empty. Well, there are quite a lot of such countries, although some, not prohibiting it in principle, however, prohibit either the high speed mode n, or the creation of an access point in general.
But one 13 channel is not enough for us - after all, we want a signal-to-noise ratio more, which means we want to launch a point with a signal strength of 30. We are looking for in CRDA,
(2402 - 2482 @ 40), (30)
channel 13, width 40 MHz, signal strength is 30. There is such a country, New Zealand.
But what is it, at a frequency of 5 GHz is required DFS. In general, this is theoretically a supported configuration, but for some reason it does not work.
Optional task, doable by people with advanced social skills:Collect signatures / movement in support of accelerated relicensing of Wi-Fi-bands in the ITU (well, or at least in your country) as a whole in the direction of expansion. It is quite possible, any deputies (and candidates), hungry for political points, will be happy to help you.

This is ravine number 4
The access point may not start if there is a DFS, without giving a reason. So, which regulatory domain should we choose?
There is such! The freest country in the world is Venezuela. Its regulatory domain is VE.
Full 13 channels of 2.4 band, with a power of 30 dBm, and a relatively relaxed 5 GHz band.
Task with an asterisk. If you have a disaster in the apartment, even worse than me, for you there is a separate bonus level.
Regulatory domain "JP", Japan, allows you to do a unique thing: to launch the access point on the mythical, channel 14. True, only in b mode. (Remember, I said that there are small differences between b and g?) Therefore, if everything is really bad at you, then channel 14 can be a salvation. But again, it is physically supported by a bit of that client device, which is the access point. And the maximum speed of 11 Mbit is somewhat discouraging.
Copy /etc/hostapd/hostapd.conf into two files, hostapd.conf.trendnet24 and hostapd.conf.cisco57
Trivially /etc/rc.d/rc.hostapd to run two copies of hostapd.
In the first, we specify channel 13. True, we indicate the signal width at 20 MHz (capability 40-INTOLERANT), because firstly, we will be theoretically more stable, and secondly, “law-abiding” access points will simply not run at 40 MHz from - because the range is clogged. We put the capability TX-STBC, RX-STBC12. We cry that the LDPC, RX-STBC123 capabilities are not supported, and the SHORT-GI-40 and SHORT-GI-20, although they are supported and slightly improve the speed, but also slightly decrease the stability, which means we remove them.
True, for fans, you can patch hostapd so that the option force_ht40 appears, but in my case it is pointless.
If you are in a strange situation when the access points turn on then turn off, then for special gourmets you can rebuild hostapd with the ACS_SURVEY option, and then the point itself will first scan the range and choose the least “noisy” channel. Moreover, in theory, it should even be able to move from one channel to another at will. True, this option did not help me, alas :-(.
So, our two points in one package are ready, we start the service:
/etc/rc.d/rc.hostapd start
The points start successfully, but ...
But the one that works on the 5.7 range is not visible from the tablet. What the hell?
Ravine number 5
Damned regulatory domain works not only on the access point, but also on the receiving device.
In particular, my Microsoft Surface Pro 3, although made for the European market, in principle does not support the 5.7 range. I had to switch to 5.2, but then at least 40 MHz mode started.
Ravine number 6
It all started. The points started, 2.4 shows a speed of 130 Mbps (it would be SHORT-GI, it would be 144.4). Why a map with three antennas supports only 2 spatial streams is a mystery.
Ravine number 7
Start something started, and sometimes ping jumps to 200, and that's it.
And the secret is not hiding at all at the access point. The fact is that according to the rules of Microsoft, Wi-Fi card drivers must themselves contain software for searching networks and connecting to them. Just like in the good old days, when the 56k modem had to have a dialer with us (which we all changed to Shiva, because the dialer that came with the standard Internet Explorer 3.0 was too terrible) or the ADSL modem had to have a client PPPoE.
But for those who do not have a regular utility (that is, everyone in the world!), Microsoft took care by doing the so-called “Wi-Fi autoconfiguration”. This autoconfiguration joyfully spits the fact that we are already connected to the network, and every X seconds scans the range. In Windows 10, there is not even a “refresh network” button. It works fine as long as the networks are around two or three. And when there are 44, the system freezes and gives a few ping 400 seconds.
"Autoconfiguration" can be disabled with the command:
netsh wlan set autoconfig enabled=no interface="???????????? ????" pause
Personally, I even made myself on the desktop two batch file "turn on autoscan" and "turn off autoscan".
Yes, I ask to pay attention that if you have Russian Windows, then most likely the network interface will have a name in Russian in the IBM CP866 encoding.
Sammari
I rolled a rather long sheet of text, and would have to complete it with a brief summary of the most important things:
1. The access point can work only in one range: 2.4 or 5.2 or 5.7. Choose carefully.
2. The best regulatory domain is VE.
3. The iw phy info, iw reg get commands will show you what you can.
4. Channel 13 is usually empty.
5. ACS_SURVEY, 20 MHz channel width, TX-STBC, RX-STBC123 will improve the signal quality.
6. 40 MHz, more antennas, SHORT-GI will increase the speed.
7. hostapd -dddtK allows you to run hostapd in debug mode.
8. For fans, you can rebuild the core and CRDA, increasing the signal power and removing the regulatory domain restrictions.
9. Auto-Wi-Fi on Windows is disabled by the netsh command. Wlan set autoconfig enabled = no interface = "???????????? ????"
10 Microsoft Surface Pro 3 does not support the 5.7 GHz band.
Afterword
Most of the materials used in writing this manual are found in either Google or in the manuscripts for iw, hostapd, hostapd_cli.
In fact, the problem is SO NOT DECIDED. At times, ping still jumps to 400 and stays at that level, even for the “empty” band at 5.2 GHz. Therefore:
I am looking for a Wi-Fi spectrum analyzer in Moscow, equipped with an operator, with which one could check what the problem is, and whether it lies in the fact that there is a very important and secret military institution nearby that nobody knows about.P.S
Wi-Fi operates at frequencies from 2 GHz to 60 GHz (less common formats). This gives us a wavelength from 150mm to 5mm. (Why do we measure the radio at frequencies and not at wavelengths? It’s also more convenient!) I, in general, have the idea to buy a quarter-wave metal wallpaper (1 mm is enough) and make a Faraday cage to be guaranteed isolated from neighboring Wi-Fi, and at the same time from all other radio equipment, such as DECT phones, microwaves and road radars (24 GHz). One problem - it will block GSM / UMTS / LTE phones, but you can select a fixed charging point at the window for them.
I will be glad to answer your questions in the comments.