[Solved] Enable Wi-Fi and Connect to a Network on First Boot

EDIT: Solved! Thanks to everyone who helped me figure this out. @lleachii @jeff @mk24 @anon50098793 :+1: See post #30 for the config files that I used to get this working.

What would need to be changed in the firmware to have my device enable the WiFi adapter and connect to a wireless network on the first boot after flashing? I know it is disabled by default but I want to build a custom firmware that I can flash from the stock firmware. I already know how to build the firmware, but I haven't used uci much. Could I edit rc.local and put some uci commands to enable WiFi and connect to a network? My device is the Netgear EX3700. It has one ethernet port and two WiFi radios. I would like to avoid removing it from where it is currently plugged in at if possible because it is in a hard to reach part of the house.

I've been playing around in a VM by using qemu-system-mips to boot the malta firmware. I was thinking that maybe qemu would be able to boot the firmware that was built for the EX3700 and I could test out the commands there before I built a custom firmware to put on the actual device.

1 Like

While looking around on a VM of the malta image, I noticed something in the file: lib/wifi/mac80211.sh

uci -q batch <<-EOF
...
set wireless.radio${devidx}.disabled=1

On the first boot is this going to override changes I make to /etc/network/wireless?

Also, when I extracted the firmware image for my device, there isn't a /etc/network directory and I don't see anything related to the wifi in the /etc/config directory.

Configure /etc/config/wireless as you wish on the target hardware. Add a copy of it to your ROM with either the FILES= directive for the image builder, or the files/ directory for a source build.

Your content would go into, for example files/etc/config/wireless

1 Like

Is it possible to extract the bin file I downloaded from openwrt.org and add the /etc/config/wireless file there, and then recompress everything back into a flashable bin file?

(I was able to extract the bin file with 7z x <bin file>)

Not in any reasonable way that is easier than the Image Builder or building from source.

1 Like

Building from source will not include LuCi by default, right? I think I want to try to configure everything through the terminal. I used LuCi the last time I had OpenWrt on this device but I think forcing myself to get familiar with uci will be better in the long run.

That's correct, starting with an empty .config and selecting the target, subtarget, and specific board will select the "minimal" set of packages for operation of the device1. The primary difference is that there is no LuCI or web server.

You can check your config against "stock" with ./scripts/diffconfig.sh

You can check that output against the config.seed from a "release" download page to see what is added to the release image that is not in your image.

You can look at, for example, near the bottom of http://downloads.openwrt.org/releases/18.06.4/targets/ar71xx/generic/config.seed to see what is added.

CONFIG_PACKAGE_libiwinfo-lua=y
CONFIG_PACKAGE_liblua=y
CONFIG_PACKAGE_liblucihttp=y
CONFIG_PACKAGE_liblucihttp-lua=y
CONFIG_PACKAGE_libubus-lua=y
CONFIG_PACKAGE_lua=y
CONFIG_PACKAGE_luci=y
CONFIG_PACKAGE_luci-app-firewall=y
CONFIG_PACKAGE_luci-base=y
CONFIG_PACKAGE_luci-lib-ip=y
CONFIG_PACKAGE_luci-lib-jsonc=y
CONFIG_PACKAGE_luci-lib-nixio=y
CONFIG_PACKAGE_luci-mod-admin-full=y
CONFIG_PACKAGE_luci-proto-ipv6=y
CONFIG_PACKAGE_luci-proto-ppp=y
CONFIG_PACKAGE_luci-theme-bootstrap=y
CONFIG_PACKAGE_rpcd=y
CONFIG_PACKAGE_rpcd-mod-rrdns=y
CONFIG_PACKAGE_uhttpd=y

A lot of the other settings are specific to the buildbots building all packages, all kernel modules, and all boards for a given target. Do not set these if you want to retain sanity!

1 There is some hidden way to dump in "pre-config" in that I forget found again:.

.config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
        @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config >/dev/null; then \
                [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
                $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
        fi
1 Like

Awesome. Thanks. I actually think I'm going to configure the wireless to start in AP mode instead of trying to get it to connect to a network. That way I connect directly to the device's WiFi network and configure it from there.

Is there a way that I can tell which radio is which by looking at the files in the bin file? It has two radios and they are both capable of using 2.4 GHz and 5 GHz. I should be able to refer to them as radio0 and radio1 in the wireless config, right? Would this be sufficient to start an AP on both radios after the first boot?


config wifi-device 'radio0'
        option type 'mac80211'
        option channel '36'
        option hwmode '11a'
        option path 'virtual/mac80211_hwsim/hwsim0'
        option htmode 'VHT80'
        option disabled '0'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'                                                   
       option ssid 'wifiRadio0'                                              
      option encryption 'none'     
                              
config wifi-device 'radio1'                                                
   option type 'mac80211'                                             
   option channel '36'                                                
   option hwmode '11a'                                                
   option path 'virtual/mac80211_hwsim/hwsim1'                        
   option htmode 'VHT80'                                              
   option disabled '0'

config wifi-iface 'default_radio1' 
   option device 'radio1'                                             
   option network 'lan'                                               
   option mode 'ap'                                                   
   option ssid 'wifiRadio1'                                              
   option encryption 'none'

EDIT: Actually, I think I'm wrong about both radios supporting 2.4 GHz and 5 GHz. I'm pretty sure one radio supports 5 GHz and the other radio supports 2.4 GHz.

Of

The ones that associate the driver with the device (and, as such are "unchangeable") include

        option type 'mac80211'
        option path 'virtual/mac80211_hwsim/hwsim0'

The others, within reason can be changed as you see fit.

In my config, I often hand-craft the name to be 'radio2' and 'radio5' or the like then refer to it with the same name in the

        option device 'radio0'

declaration in the wifi-iface section. Similarly, you can "custom name" your wireless interfaces. From one of my running mesh APs

config wifi-iface 'mesh0'
        option device 'radio5pci'
        option ifname 'mesh0'
[...]

The config line determines how UCI refers to it, the ifname is what appears in ip and the like.

26: mesh0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master bat0 state UP mode DORMANT group default qlen 1000

(rather than wlan2-3 or something seemingly random)

1 Like

Is there a way that I could find out what 'type' and 'path' need to be set to? And is there a way to find out which radio is 5 GHz and which one is 2.4 GHz?

$ wifi --help
Usage: /sbin/wifi [config|up|down|reload|status]
enables (default), disables or configures devices not yet configured.

I'd move aside your current /etc/config/wireless first

The channels selected for the "default" APs should let you tell 2.4 GHz vs. 5 GHz

1 Like

The config I posted is the default one from the malta image I'm running in a VM. The bin file for the EX3700 didn't have a /etc/config/wireless file when I extracted it.

I don't know if this would help me determine what 'type' and 'path' should be set to? I'm pretty sure the mt* files are the Wi-Fi firmwares and the rt* files are the ethernet firmwares.

~/openwrt/ex3700$ ls -1 ./lib/firmware
mt7603_e1.bin
mt7603_e2.bin
mt7662.bin
mt7662_rom_patch.bin
regulatory.db
rt2860.bin
rt3290.bin

It won’t. It’s generated automatically when missing

1 Like

If I fill everything out except 'type' and 'path' will those two settings be filled in automatically and the WiFi should come up on the first boot?

Not clear as I only use wifi config with no /etc/config/wireless in place. It would surprise me if it worked as you might hope with an incomplete /etc/config/wireless

Edit: From /lib/wifi/mac80211.sh

                uci -q batch <<-EOF
                        set wireless.radio${devidx}=wifi-device
                        set wireless.radio${devidx}.type=mac80211
                        set wireless.radio${devidx}.channel=${channel}
                        set wireless.radio${devidx}.hwmode=11${mode_band}
                        ${dev_id}
                        ${ht_capab}
                        set wireless.radio${devidx}.disabled=1

                        set wireless.default_radio${devidx}=wifi-iface
                        set wireless.default_radio${devidx}.device=radio${devidx}
                        set wireless.default_radio${devidx}.network=lan
                        set wireless.default_radio${devidx}.mode=ap
                        set wireless.default_radio${devidx}.ssid=OpenWrt
                        set wireless.default_radio${devidx}.encryption=none
EOF
                uci -q commit wireless

so, no, it will overwrite

2 Likes

Nothing is changed unless the file does not exist at all. In other words if you have an incomplete or erroneous /etc/config/wireless, the firstboot scripts won't change it at all.

Simplest thing would be to get the type and path from a working instance on the same hardware and copy it into your file.

2 Likes

So the /lib/wifi/mac80211.sh script won't overwrite the wireless config if it's already exists?

I'm pretty sure 'type' is mac80211

WikiDevi page on the EX3700:

WI1 chip1: MediaTek MT7620A
WI2 chip1: MediaTek MT7612EN

OpenWrt doc on /etc/config/wireless:

Used values are broadcom on brcm47xx, or mac80211 for all other platforms.

I'm having trouble finding anything online showing the contents of the wireless config for this device, so I'm not sure about the value of 'path'. Do you know how the /sbin/wifi command obtains that value?

Typically run-time probing. It's pretty clear in the code. Start reading at

     70         for _dev in /sys/class/ieee80211/*; do
1 Like

Thanks. That seems to suggest that I won't be able to get those values without running it on the hardware itself unless I can find someone who had posted their config somewhere.