User Tools

Site Tools


Configure A(ccess) P(oint or 'hotspot') + STA(tion or 'client')

AP+STA mode allows OpenWrt to connect to a wireless hotspot (AP) and provide wireless access from that hotspot to anything connected to the OpenWrt AP and Ethernet ports, the 'br-lan' device. This assumes that your OpenWrt device has the default settings where the AP and Ethernet port are bridged.

Manual configuration

The changes below assume an OpenWrt default configuration, the relevant files are:

Step 1: Backup the relevant configuration files

cp /etc/config/dhcp /etc/config/dhcp.original
cp /etc/config/firewall /etc/config/firewall.original
cp /etc/config/network /etc/config/network.original
cp /etc/config/wireless /etc/config/wireless.original

Step 2: Modify the relevant configuration files' sections


config dnsmasq
	option domainneeded '1'
	option boguspriv '1'
	option filterwin2k '0'
	option localise_queries '1'
# Disable rebind_protection
#	option rebind_protection '1'
	option rebind_protection '0'
# End of changes
	option rebind_localhost '1'
	option local '/lan/'
	option domain 'lan'
	option expandhosts '1'
	option nonegcache '0'
	option authoritative '1'
	option readethers '1'
	option leasefile '/tmp/dhcp.leases'
	option resolvfile '/tmp/'
	option localservice '1'


config zone
	option name		wan
# Add wwan network
 	list   network		wan
	list   network		wan6
	list   network		wwan
# End of changes
	option input		REJECT
	option output		ACCEPT
	option forward		REJECT
	option masq		1
	option mtu_fix		1


config interface 'lan'
	option ifname 'eth0.1'	# device dependent
	option force_link '1'
#	option macaddr 'xx:xx:xx:xx:xx:xx'
	option type 'bridge'
	option proto 'static'
# Change the default OpenWrt IP address
# Note that OpenWrt AP IP address must be in a different subnet than the hotspot (AP) IP address.
	option ipaddr ''
# End of changes
	option netmask ''
	option ip6assign '60'

# Add the following section
config interface 'wwan'	# 'wireless WAN'
	option	proto	'dhcp'	# launches udhcpc
# End of addition


config wifi-device radio0
	option	type	mac80211
	option	channel	11	# any supported channel or 'auto'
	option	hwmode	11g	# any supported mode or driver default
#	option	path	'10180000.wmac'
	option	htmode	'HT20'	# any supported mode or driver default  

# Add the following Section (the STA that connects to the hotspot / AP)
config wifi-iface
	option	device	radio0
	option	network	wwan	# matches interface value in /etc/config/network
	option	mode	sta	# launches wpa_supplicant
# The encryption and ssid values need to match those of the hotspot (AP)
	option	encryption none # not recommended for deployment
#	option	key	super_secret_key
	option	ssid	"hotspot or AP ssid" # framing quote / apostrophe required (embedded 'blank')
# End of changes

config wifi-iface
	option	device	radio0
	option	network	lan
	option	mode	ap
	option	ssid	OpenWrt # ssid for wireless clients
	option	encryption none # not recommended for deployment
#	option	key	everybody_knows_this_key

⇒ An alternative event-driven recovery solution is to be found here.⇐

Step 3: Revert to AP Only mode on boot when Hotspot is not available

When the hotspot is not available or it is incorrectly defined in the wireless configuration file, OpenWrt will disable the AP. This means that you can only access your OpenWrt device through its Ethernet port. The following will describe how to get OpnWrt to test for the hotspot availability after boot. If OpenWrt can not connect to the hotspot after 30 seconds, OpenWrt will automatically reconfigure itself to AP Only mode. This will allow wireless access to your OpenWrt device again.

Step 3.1: Create AP Only and AP+STA wireless configuration files

cp /etc/config/wireless.original /etc/config/wireless.ap-only
cp /etc/config/wireless /etc/config/wireless.ap+sta

Step 3.2: Install script

Make sure that package iwinfo is installed. Place the following text in /usr/local/bin/

# Fix loss of AP when STA (Client) mode fails by reverting to default
# AP only configuration. Default AP configuration is assumed to be in
# /etc/config/wireless.ap-only
while [ $(iwinfo | grep -c "ESSID: unknown") -ge 1 ]; do
   let sta_err=$sta_err+1
   if [ $((sta_err * SLEEP)) -ge $TIMEOUT ]; then
     cp /etc/config/wireless.ap-only /etc/config/wireless
     wifi up
#    uncomment the following lines to try AP+STA after reboot
#    sleep 3
#    cp /etc/config/wireless.ap+sta /etc/config/wireless
   sleep $SLEEP

Step 3.3: Make executable

chmod +x /usr/local/bin/

Step 3.4: Add /etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/bin/sh /usr/local/bin/ > /dev/null &
exit 0

Step 4: wwanHotspot: maintain allways up a dual wifi config, Access Point and HotSpot client

In one place there may be several Hotspots that may be available or not according to the comings and goings of their owners; we will enter the parameters of each one of them in the configuration file therefore wwanHotspot will connect and disconnect the OpenWrt HotSpot client to one of them as they become available.

This daemon may be used instead of the method described in Step 3.

Step 4.1: install

Download the latest version from GitHub wwanHotspot and follow the instructions.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
docs/guide-user/network/wifi/ap_sta.txt · Last modified: 2019/08/30 23:46 by tmomas