OpenWRT and WLAN-USB-Sticks (Updated with an example)

USB-WiFi support in OpenWRT

Recently one of my blog’s visitors (Michael) asked me, if it was possible to extend his router with an additional USB-Wifi device. The short answer is: yes.
I’ll give you an example of a tested configuration below. If you are planning to use different parts, please check the  caveats here and be sure to get chipsets, that are known to work.

So here is a example setup:
  • TP-Link TL-WR1043NDv2
  • CSL 300 Mbit Dual Band WLAN USB Stick from Amazon (they sell it as a raspberry pi extension). Yes, you can regulate power and even replace antennas. It seems to be fully capable of DFS and TPC out of the box.
  • an USB stand
Plug the stick in the USB stand and connect the cable to your TL-WR1043NDv2’s USB port. lsusb should show:

Bus 001 Device 002: ID 148f:5572 Ralink Technology, Corp. RT5572 Wireless Adapter

While connected to the internet run

opkg update

Then get Ralink kernel modules:
opkg install kmod-rt2800-usb
Opkg will probably install some more drivers (kmod-rt2x00-usb), but “rt2800usb” is the one needed.
If you now look into your LuCI-Webinterface, you won’t see a difference in “Network”, “Wireless”, why? Short answer: your /etc/config/wireless configuration file does not know about your new wifi interface. Do …

cd /etc/config
mv ./wireless ./wireless.bak
wifi detect >> ./wireless
cat wireless.bak >> ./wireless

You’ll create a new wifi interface configuration that way and append the existing configuration to it.

You should now edit /etc/config/wireless and remove duplicate lines/duplicate (dummy) blocks for your existing radio0 (thats d-d for deletion of single lines. Save and exit (ESC:x).
To be sure, the changes are recognized do

/etc/init.d/uhttpd restart

Login to LuCI, go to “Administration”, “Network”, “Wireless” and configure your new radio accordingly.
If you like, you can add “option antenna_gain 5” to your radio1 config in /etc/config/wireless. That way transmit power can never exceed regdomain limits. (E.g. 28db shown by iw list minus antenna gain (dBi) 5 is 23. That’s 200 milliwatt EIRP.
Some Realtek adapters may not be that easy to configure, especially when they need device firmware to be uploaded, but it can probably be done, as long as your Router has enough flash for a bunch of drivers and firmware.
Have fun, but check the caveats:
Here’s a list of things to keep in mind when trying this:
  • Do research on whether the dongle is supported by linux in general.
    • does it need additional (FullMac) firmware? Yes: could be a problem. No, continue.
    • Support for ndiswrapper only … forget about it…
  • Compare, if OpenWRT’s (older) linux kernel supports this dongle, too.
  • Look for a commonly available chipset (Realtek ™ rtl8192u/su/cu; Atheros ™ ‘carl’)…
  • Keep in mind, that most cheap WiFi sticks (€5-15) won’t let you regulate the transmission power.
    • If the stick’s original antenna is detachable, you therefore must not use it in combination with a replacement antenna of higher gain. (Usually OEM antennas have a relational gain of 2dB to 5 dB).
      • Example: “High gain” usb stick has a fixed txpower of 15dB(dBm) and is packaged with a 5dBi omnidirectional antenna. The resulting transmission power will be 20dB (dBm), which is perfectly legal (EIRP must not exceed 20dB in Europe within 2.4 GHz; for 5GHz higher values apply, but these depend on additional factor, which are beyond the scope of this post).

If e.g. you have a router running OpenWRT, and that router is equipped with an USB port, you may connect your dongle to the router.

  • Run the command lsusb. It will tell you, the manufacturer and device id in hexadecimal format.
  • Use Google or any other websearch for this term. You may narrow the search by adding ‘openwrt’, ‘linux’, ‘linux driver’ and so on.
    • The search hopefully will tell you, whether the dongle is supported by your version of OpenWRT and tell you more about the steps to take.
  • You may need to install additional modules since OpenWRT binaries don’t ship with all drivers included. The easiest way to do this, is to use LuCI. Click “Administration” in your routers web interface and log in to it. Now go to ‘System’, ‘Software’ and update the package lists. The module you are looking for will start with ‘kmod-‘. If you are unsure, use a websearch again.
    The module should be loaded on the next reboot, if it isn’t you can modify /etc/rc.local from within the shell, in order to do so and reboot again.
  • You should see a new radio now (‘Administration’/’Network’/’Wireless’). If not, start a shell and check ifconfig (is the device here? if not…), dmesg (Error loading driver? Missing firmware?) and logread (if it is another problem).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s