I am not responsible if your devices send you back in time, explodes, implodes, bricks or flies into space from the use of any software I put up.


Saturday, July 16, 2011

Hacking TP-Link WR1043ND Part 4

To Tweak the OpenWRT for Pure Performance there is no other way than editing config files from Terminal so I hope you actually read Part 3 before.
There are 4 parts to Tweaking the Performance
  1. Wireless Performance
  2. Wired Performance
  3. Web Performance
  4. QoS (Quality Of Service)
  5. Overclock the Router
Tweaking Wireless Performance:

Setting to Wireless N with G backward compatibility

The TP-Link WR1043ND Hardware has a 3 Transmit 3 Receive Radio that is only Single Band with 20/40MHZ  Frequency. It has Wireless B/G/N Capability.
To fully understand WiFi Standards you need to read up on IEEE 802.11 standards.
We start by tweaking the Radio.

Wireless N allows backward compatibility with B and G, you need to set it to 802.11g+n.
You can do this by logging into the Router via Putty using vi editor edit the file called "wireless" in /etc/config/, or do it in LuCI Web Interface(Router Config Page).

Adjusting Channel Width:

Next you need to make sure the Router is using 40MHZ Channel Width, this will allow greater throughput.
You can do this by logging into the Router via Putty using vi editor edit the file called "wireless" in /etc/config/
config 'wifi-device' 'radio0'
        option 'type' 'mac80211'
        option 'channel' '7'
        option 'macaddr' 'XX:XX:XX:XX:XX:XX'
        option 'hwmode' '11ng' #Wireless G and N Modes
        option 'htmode' 'HT40-' # Set to 2.4GHZ 40MHZ Fat Lower(-) Channel
        option 'noscan' '1' # Enable neighbour 'unfriendly' WiFi Settings
        option 'country' 'US'
        list 'ht_capab' 'SHORT-GI-40'
        list 'ht_capab' 'DSSS_CCK-40'
        option 'disabled' '0'
        option 'txpower' '24'
config 'wifi-iface'
        option 'device' 'radio0'
        option 'network' 'lan'
        option 'mode' 'ap'
        option 'ssid' 'Your_SSID_Here'
        option 'encryption' 'psk2'
        option 'key' 'your_secret_key_here'
Note that there are 2 htmodes, HT40+ and HT40- you set them based on the channel available. If you set it wrongly you have to log in to the router via Ethernet Cable and change it back.
By rights 'htmode' is not allowed if there are competing BSSID using that channel (the good neighbor regulation), but you can override that with 'noscan' option. There is also a distance optimization setting which I tested the best values at 20-25.

Below is a graph displaying the difference between 40MHZ Channel Width and 20MHZ Channel Width.
Note that you can define more than 1 Access Point on OpenWRT. You can configure a Second AP as Guest and Fire-walling it from your own LAN.

Higher TXPower (Transmit Power)

Transmit Power allows you to resize the cell. Max Value is 24 only works with US regulatory settings.
You can also try placing the Wireless Router at a higher position for better signal strength.

Tweaking Wired Performance:

Next you need to make sure the Router Ethernet Performance is adjusted by changing the sysctl variable this will allow greater throughput.
You can do this by logging into the Router via Putty using vi editor edit the file called "sysctl.conf" in /etc/

# The following 3 lines helps to ensure Router will always have
# sufficient memory and will not crash during samba file copy

# Use ipv6

# disable bridge firewalling by default
# Increase TCP max buffer size setable using setsockopt()
# 2 MB might be enough for some very long end-to-end paths
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
# Increase Linux autotuning TCP buffer limits
# min, default, and max number of bytes to use
# (only change the 3rd value, and make it 2 MB or more)
net.ipv4.tcp_rmem = 4096 87380 2097152
net.ipv4.tcp_wmem = 4096 65536 2097152
# The following 2 lines enable ipv6 privacy mode
All the TCP tweaks are derived from ESnet
Note: These tweaks are not found on OpenWRT How Tos, however I soon discovered that someone is working on bufferbloat hence the tweaks on buffersize should be approached with caution.

Also if you have a Windows File Share you want to tell the Router firewall not to monitor SAMBA Packets.
Windows Share also known as SAMBA in Linux uses the Port 445 so you need to tell OpenWRT to stop monitoring Packet Originating from LAN using Port 445.

Tweaking Web Performance:
Web Peformance typically require a lot of DNS Look up so you want to tell OpenWRT to use the Fastest DNS Server available.
You can do this by logging into the Router via Putty using vi editor edit the file called "dnsmasq.conf" in /etc/ or do it in the file /etc/config/dhcp
and add the fastest DNS Server closest to you.
Add the Line Below and change the IP of the server to YOUR fastest DNS Server. My Fastest DNS Servers may not be your Fastest DNS Server.
Blue is a Singapore ISP DNS Server, Green is Google DNS Server, Red is OpenDNS Server.
There is no limit of the number of DNS Server you can set on OpenWRT

Quality of Service                    

What is Quality of Service?
Quality of Service makes it so that during torrenting, your webpages doesn't take a long time to load even though you are on a 1Mbps Connection.
It does this by prioritizing network traffic, putting webpage network packets in higher importance than torrent packets.
The step to installing QoS is logging into the Router via Putty then
opkg install luci-app-qos
You set the QoS by setting the Port the Network Originate from and the Priority. Or you can set layer 7 filter to detect torrent traffic. Note that Layer 7 filtering is processor intensive activity and might cause the routing performance of the router to drop.

Hopefully you learn a lot from this series of blog post and enjoy the high performance of your Modified Router running on OpenSource Software.
If you run a Windows Share Server when you place the laptop beside the router and do a copy you should be getting insane WiFi Speeds @ 150Mbps at 5m line of sight
Let the numbers speak for themselves!

In case you modified the wrong config files and got lock out the fail safe mode is here.

If you are interested I have a OpenWRT built for TL-WR1043ND that I use personally myself. It is optimized to my satisfaction for pure performance.
You can get it here.
If you actually tried my firmware you will find that all the tweaks I listed above have been already added to the firmware defaults so there is nothing additional to tweak.


db260179 said...

Thanks for the tutorial.

Only one suggestion. Do not install the haproxy as it stops the web interface from coming up and you will get a '503 error'.

vmlinux said...

Very nice dude, I just started playing with the TP-LINK WR1043ND V1.8, and it's a smoking little router for the price, the best I've found. I knew some of these tricks, but stuff like the wifi channel width was very enlightening to me.

tux said...

First thank you for the guide,

however, I got no idea why my wr1043nd get crashed if I applied HT40, any idea?

Thomas Andrew Morris said...

Hi Admin,

Thanks for the build I trying both this and 4300!

using your build:
OpenWrt Attitude Adjustment r33335 / LuCI Trunk (trunk+svn9238)

no longer supports:


Any ideas?

Przemek Przemek said...

Great tutorial !! Thanks a lot.

Especially adding "no tracking" for Samba, boosted copying large files in my case :)

However I wonder it is ok to increase buffers and queue depth without DDR upgrade from 32 to 64 MB ???