May 162013
 

So lately, I’ve been trying to use one of my Raspberry Pis as a WiFi bridge.
That is connecting the Pi to a WiFi network, and sharing it out via the ethernet port.
I was trying to do that with the RT5370 USB sticks that I was also using to broadcast hotspots.

With the default drivers in Raspbian however, trying to add wlan0 to a bridge results in this message

can't add wlan0 to bridge br0: Operation not supported

According the the drivers, wlan0 can’t do it.
The only way to add the RT5370 NIC to a bridge is to activate 4addr (4 address frame) mode.

iw wlan0 set 4addr on

However, once 4addr mode is on, traffic between the WiFi device and the AP seemed to stop altogether.

The solution to this issue, is to use the RALink drivers. The vendor drivers does not seem to use the Linux WiFi stack however, which means that those drivers can not be used to broadcast a hotspot using hostapd. So if you’re using a Pi as a WiFi repeater, you may have issues there, though that will be something I’m going to experiment with later as well.

Preparation

Before we can actually compile the drivers, we’re going to need to grab the kernel sources.
I’m using Raspbian Server Edition, which uses the 3.6.11+ kernel. We’ll need the matching source from github.
We’ll change to the /usr/src directory first, then wget the sources from github, and then untarball it with these commands.

*Note* I’m doing it as root, so you can either prepend sudo to these commands, or run sudo bash before running these commands.

cd /usr/src
wget https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz
tar -xvzf rpi-3.6.y.tar.gz

Once the source is extracted, we’ll need to copy the current kernel configuration into the source directory.

cd linux-rpi-3.6.y
gzip -dc /proc/config.gz > .config

And then we need to create the files and symlinks neccesary for compiling external modules

make modules_prepare
ln -s /usr/src/rpi-3.6.y /lib/modules/3.6.11+/build

Compiling the Vendor drivers

In order to use the Vendor drivers, first we’ll need to get them.
The drivers can be found here.
Download the ones for the RT5370 and transfer it to the Pi as we’ll need to compile the drivers ourselves.

Once we have the drivers on the Pi, we’ll move them to /usr/src and untar them to keep things nice and neat. Assuming the drivers are in /home/pi
*Note* Again I’m doing everything as root.

mv /home/pi/2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2 /usr/src
cd /usr/src
tar -xvjf 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2
cd 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0

Once it’s untarred, we’ll need to edit the file ‘os/linux/config.mk’ to enable WPA support and to allow network managers to control the device.
So find these lines, and change the n to y, then save and close the file.

HAS_WPA_SUPPLICANT=n
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n

Now, we should still be in the /usr/src/2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0/ directory.
Time to compile the drivers !
To compile them, we just need to run the ‘make’ command in the drivers directory as root.
It took me just shy of 12 minutes to compile the drivers on a Class 4 SD Card on a non-overclocked pi.
Once they are compiled, running ‘sudo make install’ will install the drivers into the right spot

To make sure the drivers are installed properly, we’ll load the module to make sure no errors come up.
*Note* Run this as root again

modprobe rt5370a

If no errors come up, then that’s a good sign. Check that it’s been loaded by running lsmod and checking the output.

root@raspberrypi:/home/pi# lsmod
Module Size Used by

rt5370sta 786186 0

You should see the module rt5370sta in the list there.
Lastly we’ll disable the rt2800 usb module and enable autoloading of the new rt5370sta module.
We’ll need to edit /etc/modprobe.d/raspi-blacklist.conf and add the following line to the end

blacklist rt2800usb

And then we’ll need to edit the /etc/modules file to add the new module we’ve just compiled. Just need to add the module name to the end of the file

rt5370sta

After the file has been modified, reboot the Pi and when it comes back up, run ifconfig -a and you should see something similar to the following –

eth0 Link encap:Ethernet HWaddr b8:27:eb:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:354 errors:0 dropped:0 overruns:0 frame:0
TX packets:181 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30609 (29.8 KiB) TX bytes:25948 (25.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ra0 Link encap:Ethernet HWaddr 00:0f:54:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:854641 (834.6 KiB) TX bytes:44800 (43.7 KiB)

Notice the ra0 rather than wlan0. This shows that the Pi is using the new rt5370sta module rather than the old rt2800usb one. You can still use the ra0 interface to connect to wireless networks like normal.

Share

  20 Responses to “How To : Use A RT5370 USB WiFi NIC In A Bridge”

  1. Hello SirLagz,

    Is it 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2 or 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2, DPO for letter O not zero.

    After I issue a command “make”, got these errors:

    make: *** /lib/modules/3.6.11+/build: No such file or directory. Stop.
    make: *** [LINUX] Error 2

    I made a “build” folder then these errors came out:

    make[1]: Entering directory `/lib/modules/3.6.11+/build’
    make[1]: *** No rule to make target `modules’. Stop.
    make[1]: Leaving directory `/lib/modules/3.6.11+/build’
    make: *** [LINUX] Error 2

    any ideas what those errors mean?

    • You need to compile some modules first from the kernel source.
      I need to update this post, sorry !

      • When you update, will you include the modules needed?

      • I’m stuck at this part as well. Did you update the post with the other required modules that needed compiling?

        • The only one that needed compiling should have been the rt5370sta module…unless I’m getting confused about what you mean
          I haven’t updated the post yet though. I’ll see if I have the time to do it tonight.
          The alternative is to grab the module.symvers file from github.

  2. Thank you for providing such an excellent write-up! This addressed exactly the problem I had when trying to use an N150 adapter with the RA5370 chipset.

    I came across one typo. The following line should be changed from:

    ln -s /usr/src/rpi-3.6.y /lib/modules/3.6.11+/build

    To:

    ln -s /usr/src/linux-rpi-3.6.y /lib/modules/3.6.11+/build

    Also, I encountered the following error while compiling the manufacturer drivers:


    WARNING: Symbol version dump /usr/src/linux-rpi-3.6.y/Module.symvers
    is missing; modules will have no dependencies and modversions.

    The modules compiled and installed, but would not load. The following error was reported:


    $ sudo modprobe rt5370sta
    ERROR: could not insert 'rt5370sta': Exec format error

    I fixed this by downloading the Module.symvers file from the raspberry-pi project on Github:

    $ cd /lib/modules/3.6.11+/build
    $ sudo wget https://github.com/raspberrypi/firmware/raw/master/extra/Module.symvers

    • Hi Scott,

      Thanks for reading !
      That “typo” is dependent on how you extract the kernel, if you’ve extracted the source to /usr/src/rpi-3.6.y then you use that, or if you’ve extracted it to /usr/src/linux-rpi-3.6.y, then you use that. Up to you which directory you use 🙂

      Also, thanks for the location of Module.symvers, I must have forgot to include it in the blog post haha

  3. Hello SirLagz, would you share compiled rt5370sta module in binary form ?

    I will be very grateful
    ivast

  4. Dear All,

    Thank you for this tutorial.

    I am face to the following error when launching the modprobe rt5370a command

    kmod_search_moddep: could not open moddep file ‘/lib/modules/3.6.11+/modules.dep.bin’

    Have you maybe an idea to solve the problem ?

    Thank you,

    Jean

  5. I followed your guide (above) and this post here: http://www.raspberrypi.org/phpBB3/viewtopic.php?p=244329&sid=9213ad056f2214923bca349796a45382#p244329

    The pi connects over wireless and creates a bridge. I can ssh to the pi using that address. The pc connected to the eth0 port DOES obtain an IP address through the pi bridge (from a separate DHCP server on my network), however no other traffic (pings/http) seems to work. Any advice?

    ——————————————————————-
    pi@raspberrypi /etc $ sudo brctl show
    bridge name bridge id STP enabled interfaces
    br0 8000.000f541594e4 no eth0
    ra0
    ———————————————————————-
    pi@raspberrypi /etc $ ifconfig
    br0 Link encap:Ethernet HWaddr 00:0f:54:15:94:e4
    inet addr:192.168.10.245 Bcast:192.168.10.255 Mask:255.255.255.0
    inet6 addr: fe80::20f:54ff:fe15:94e4/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:4529 errors:0 dropped:0 overruns:0 frame:0
    TX packets:447 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:351512 (343.2 KiB) TX bytes:52307 (51.0 KiB)

    eth0 Link encap:Ethernet HWaddr b8:27:eb:19:2b:11
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:2232 errors:0 dropped:0 overruns:0 frame:0
    TX packets:2021 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:148088 (144.6 KiB) TX bytes:367057 (358.4 KiB)

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

    ra0 Link encap:Ethernet HWaddr 00:0f:54:15:94:e4
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:2417742 (2.3 MiB) TX bytes:290076 (283.2 KiB)

    ————————————————————————–

    • You’ll need to setup ebtables to forward packets after that point. I haven’t actually gotten it working properly though =/

  6. Nice writeup on this. Have you tried running hostapd with this driver? I tried and I get an error from hostapd saying the driver doesn’t support AP mode. I went back and re-compiled the driver, turning on hostapd support by setting HAS_HOSTAPD_SUPPORT=y in config.mk but still no luck 🙁

    I’m going to try again b/c I found a newer driver:

    http://www.mediatek.com/en/downloads/rt8070-rt3070-rt3370-rt3572-rt5370-rt5372-rt5572-usb-usb/

    Love to hear your input on this. Thanks!

    • I tried the same thing you did but I didn’t have any luck either. I haven’t had the time to look into it recently but if I get the chance and find out some more, I’ll report back 🙂

      • Great, thanks! Just a little update on my end:

        I thought the issue might be related to hostapd using the nl80211 driver to run, which in turn uses cfg80211. There’s an option in the driver’s config.mk for HAS_CFG80211_SUPPORT, so I tried setting that to =Y but then I get errors and the driver won’t compile.

        Also, just FYI, the reason I’m trying to get this working is to overcome the issues described here: https://github.com/raspberrypi/linux/issues/371.

        When I’m running hostapd with the rt5370 adapter using the default rt2800usb driver and I have high network traffic over wireless I’m seeing floods of “rt2800usb_entry_txstatus_timeout: Warning – TX status timeout” in journalctl and dmesg and performance degradation. Turning off wireless n in hostapd helps, but doesn’t fully resolve the issue. I’m hoping that getting the ralink driver working will allow me to run hostapd in wireless n mode with good performance.

        Thanks for looking at this!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

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