AP+STA mode for OpenWRT on Broadcom-based Wireless Routers

(Yes, I mean the Linksys WRT54GL, WRT54G and others)
A.K.A. wireless repeater mode: both client and access point

Made possible by the collective wisdom of the Internets
Compiled by Jimmy Angelakos <vyruss@hellug.gr>

We will use WPA2 encryption for all WLAN links.

  1. Make sure your WRT54GL (or other) is running the latest OpenWRT
    firmware, using the Linux 2.4 kernel so that we can take advantage of
    the Broadcom driver to do our magic.

    At the time of writing, the latest OpenWRT release is 10.03.1
    (Backfire). You can download it at:

    http://downloads.openwrt.org/backfire/10.03.1/brcm-2.4/

    You want openwrt-wrt54g-squashfs.bin if you are installing through
    the Linksys web interface
    (Administration -> Firmware Upgrade)

    OR openwrt-brcm-2.4-squashfs.trx if you are upgrading from a previous
    OpenWRT version
    .

    Install HOWTO for WRT54G: http://wiki.openwrt.org/toh/linksys/wrt54g

    Let's assume that your OpenWRT router uses the default LAN IP address:
    192.168.1.1

  2. Let's say your ADSL modem has the IP address 192.168.0.1 and that the
    WiFi network's name (ESSID) is "MyWireless".

    You need to configure two network zones in your WRT54GL, the wan zone
    will be accessing the ADSL router and the lan zone will be the WiFi
    (or wired) network served by your WRT54GL. They will require different
    IP ranges, so the wan zone will use 192.168.0.xxx and let's say the lan
    zone will use 192.168.1.xxx .

    You can configure this via OpenWRT's LuCI web interface, but the
    quickest way will be to login with SSH into your OpenWRT router and edit
    the configuration files by hand:

  3. Your OpenWRT wireless configuration is found in the file
    /etc/config/wireless and needs to look like this:

    config wifi-device  wl0
            option type       'broadcom'
            option channel    'XX' # This is your ADSL-WiFi router's channel
    
    config wifi-iface
            option device     'wl0'
            option network    'wan'
            option mode       'sta'
            option ssid       'MyWireless'
            option encryption 'psk2'         # WPA2 for security
            option key        'wifikey1'     # Your existing WiFi password
    
    config wifi-iface
            option device     'wl0'
            option network    'lan'
            option mode       'ap'
            option ssid       'MyWirelessExtender'
            option encryption 'psk2'
            option key        'wifikey2'     # Your extender's WiFi password
    

    You can edit this by using vi: (<Esc> followed by :wq saves & exits vi)
    root@WRT54GL:~# vi /etc/config/wireless

  4. Now you need to edit the network configuration:
    root@WRT54GL:~# vi /etc/config/network

    It needs to look like this:

    config 'switch' 'eth0'
            option 'enable' '1'
    
    config 'switch_vlan' 'eth0_0'
            option 'device' 'eth0'
            option 'vlan' '0'
            option 'ports' '0 1 2 3 5'
    
    config 'switch_vlan' 'eth0_1'
            option 'device' 'eth0'
            option 'vlan' '1'
            option 'ports' '4 5'
    
    config 'interface' 'loopback'
            option 'ifname' 'lo'
            option 'proto' 'static'
            option 'ipaddr' '127.0.0.1'
            option 'netmask' '255.0.0.0'
    
    config 'interface' 'lan'
            option 'type' 'bridge'
            option 'proto' 'static'
            option 'netmask' '255.255.255.0'
            option 'ipaddr' '192.168.1.1'            # Your OpenWRT's lan IP
            option 'defaultroute' '0'
            option 'peerdns' '0'
            option 'gateway' '192.168.0.1'           # Your ADSL modem's IP
            option 'dns' '192.168.0.1'               # Your ADSL modem's IP 
            option 'ifname' 'eth0.0'
    
    config 'interface' 'wan'
            option 'proto' 'static'
            option 'netmask' '255.255.255.0'
            option 'defaultroute' '0'
            option 'peerdns' '0'
            option 'ipaddr' '192.168.0.2'            # Your OpenWRT's wan IP
            option 'gateway' '192.168.0.1'           # Your ADSL modem's IP
            option 'dns' '192.168.0.1'               # Your ADSL modem's IP
            option 'ifname' 'eth0.1'
    

  5. Reboot your OpenWRT and enjoy your new network setup:
    root@WRT54GL:~# reboot

  6. Optional step:
    You may want to hide the original WiFi network. This is not terribly
    secure, but it's convenient as you don't see too many SSIDs. Choose
    "Hide ESSID" from your ADSL modem's wireless settings. The connection
    will still work, but you'll only see the "MyWirelessExtender" network :)