Configuring AP and STA in OpenWrt

To configure a device in OpenWrt to function simultaneously as an AP (Access Point) and STA (Client) for network bridging, the following steps must be completed. This configuration allows the device to connect to an upstream WiFi (STA mode) while providing wireless access to downstream devices (AP mode), enabling network extension or use when a suitable wireless card is not available for verification.

1. Preliminary Preparation

  1. Hardware Compatibility Check Log in to the OpenWrt device via SSH and execute the following commands to view wireless chip information:

    lspci | grep -i wireless  # PCI interface devices
    lsusb                # USB interface devices
    
    
    
    

    Confirm driver support for AP+STA concurrent mode.

2. Configuring STA Mode (Connecting to Upstream WiFi)

  1. Configuration via LuCI Interface

  • Navigate to Network > Wireless, click Add to create a new interface.
  • Select the wireless device (e.g., <span>radio0</span>), set the mode to Client (STA).
  • Scan and select the target WiFi SSID, and enter the authentication information (PSK password).
  • Save and apply, ensuring the STA interface (e.g., <span>wwan</span>) successfully obtains an IP address.
  • Manual Configuration File Editing (Optional) Modify <span>/etc/config/wireless</span> to add the STA configuration block:

    config wifi-iface 'sta'
        option device 'radio0'
        option mode 'sta'
        option ssid 'Upstream WiFi Name'
        option encryption 'psk2'
        option key 'WiFi Password'
        option network 'wwan'
    
    
    
    
  • 3. Configuring AP Mode (Providing Downstream Access)

    1. Creating AP Interface

    • On the Network > Wireless page, click Add to create a new interface.
    • Select the same or another wireless device (must support concurrent operation), set the mode to Access Point (AP).
    • Set the SSID, encryption method (e.g., WPA2-PSK), and password; the encryption method and password for both AP and STA must be the same.
  • Configuration File Example

    config wifi-iface 'ap'
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt_AP'
        option encryption 'psk2'
        option key 'ap_password'
        option network 'lan'
    
    
    
    
  • 4. Network Bridging and Firewall Settings

    1. Bridging STA and AP Interfaces

    • In the physical settings, check the corresponding wireless device for AP (e.g., <span>radio0.ap</span>) and the STA interface (e.g., <span>wwan</span>).
    • Enable the DHCP server to assign IP addresses to downstream devices.
    • Go to Network > Interfaces, and edit the LAN interface:
  • Firewall Rules

    • Allow IPv4 and IPv6 traffic from LAN to WAN.
    • Ensure the LAN zone includes the AP interface, and the WAN zone includes the STA interface.
    • Add forwarding rules (Network > Firewall > Traffic Rules)
    • Or simply disable the firewall

    5. Advanced Configuration (Relay Mode)

    If you need to maintain the same subnet, use <span>relayd</span><span> to achieve seamless bridging:</span>

    1. Install the Relay Daemon

      opkg install relayd
      
      
      
      
    2. Configure Relay Interface

      config interface 'relay'
          option proto 'relay'
          option network 'lan wwan'
      
      
      
      

    6. Verification and Troubleshooting

    1. Connection Test

    • Connect a downstream device to the AP’s SSID and test internet access.
    • Execute <span>ping 8.8.8.8</span> to verify connectivity.
  • Log Analysis

    logread | grep -i wireless  # View wireless module logs
    iw dev                # Check wireless interface status
    ifconfig wlan0           # Confirm STA interface IP acquisition
    
    
    
    
  • 7. Common Issues

    Issue Phenomenon Solution
    STA cannot connect to upstream WiFi Check driver support, password correctness, and frequency band compatibility (2.4G/5G)
    AP device cannot obtain IP Ensure the LAN interface has DHCP enabled and the firewall is not blocking DHCP requests
    High network latency or disconnection Adjust wireless bandwidth (20MHz), avoid channel interference, and check signal strength

    By following the above steps, the OpenWrt device can achieve AP+STA bridging mode, suitable for wireless relaying, signal extension, and peer-to-peer performance testing scenarios.

    Leave a Comment