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.
The changes below assume an OpenWrt default configuration, the relevant files are:
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
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/resolv.conf.auto' 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 '192.168.2.1' # End of changes option netmask '255.255.255.0' 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.⇐
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.
cp /etc/config/wireless.original /etc/config/wireless.ap-only cp /etc/config/wireless /etc/config/wireless.ap+sta
Make sure that package iwinfo is installed. Place the following text in
#!/bin/sh # # 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 # TIMEOUT=30 SLEEP=3 sta_err=0 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 break fi sleep $SLEEP done
chmod +x /usr/local/bin/fix_sta_ap.sh
# 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/fix_sta_ap.sh > /dev/null & exit 0
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.
Download the latest version from GitHub wwanHotspot and follow the instructions.