Boost WIFI Speed by Forcing 40 MHz Channels in hostapd on RPi

802.11n can double the channel bandwidth of 802.11g from 20 MHz to 40 MHz, but this operation mode is not recommended in areas that the spectrums are congested and likely interfere with existing WIFI and bluetooth devices. As a result, hostapd will not enable 40 MHz when it finds other channels are being used, like what is seen from the hostapd log below:

However, this is unrealistic in modern cities. You should be grateful the primary channel you choose has not been used already, let alone the additional one for 40 MHz. What can we do? We have to force hostapd to turn on 40 MHz anyway. But since hostapd does not have any configuration options for that, we have to recompile hostapd from source. Actually, this has been done in other distros. For example, OpenWRT and Arch has patched their hostapd with the noscan patch, which adds an option to force 40MHz mode regardless of the environment.

Before turning on 40 MHz, the iwconfig on my laptop is like this, notice the bit rate is only 54 Mb/s:

Now let us start. First you need to add a deb-src source to apt so that we can download source packages. Note that I am still using Raspbian Wheezy. If you use Jessie, change the deb-src line according to your original deb line.

Save the following patch into a file:

Because we are going to create a new hostapd package, it’d be a good practice to increment the version number by adding a new section at the top of debian/changelog, like this:

Now we are ready to compile the packages:

If it succeeds, install the new package with dpkg -i.

Restart hostapd, it should now force 40 MHz mode:

And my iwconfig output now shows Bit Rate is 150 Mb/s, yay!

5 thoughts on “Boost WIFI Speed by Forcing 40 MHz Channels in hostapd on RPi”

  1. Is there any option for Pi3 and integrated wifi? I’m trying by editing hostapd to change channel width to 40MHz but it doesn’t seem to work…

  2. hi i am trying to use hostapd for wifi access point creation with the aim of getting aroung 500 Mbps speed ,my wifi card support maximun of 800 Mbps

    below are working conf file with hw_mode=g but i am gettimg maximim of 24 Mbps if i change hw_mode=a and channel = a hostapd failed to start any idea to make hostapd to work for maximim throughput i am using inter wifi card


  3. Worked like a charm, even on the latest WPA-2.4
    It would be much more comfortable to have a config option to change force 40mhz or not.
    OpenWRT hasnthat implmented already but it requires to patch more files

    Thanks for the cool tutotial

  4. Everytime I try to download the source I keep getting the following message:

    Picking ‘wpa’ as source package instead of ‘hostapd’
    E: Unable to find a source package for wpa

    Is there anyway to fix this?

Leave a Reply

Your email address will not be published.

+ 2 = six

This site uses Akismet to reduce spam. Learn how your comment data is processed.