I want to create some wireless configuration on an image at first boot. I thin uci-defaults is the normal place to do that, so I put a script in there something like this:
_load_2g_device_defaults() {
local config="$1"
# Only set up one 2g device
[ -z "$has_2g_device" ] || return 1
config_get device_band "$config" band
[ "$device_band" = "2g" ] || return 1
uci set wireless."${config}".disabled="0"
uci set wireless.default_"${config}".disabled="0"
uci set wireless.default_"${config}".ssid="${ssid}-2g"
uci set wireless.default_"${config}".key="abcd1234"
uci set wireless.default_"${config}".encryption="psk2"
uci set wireless.default_"${config}".network="lan"
}
config_foreach _load_2g_device_defaults wifi-device
That works kind of sometimes. The issue seems to be that the wifi-device configuration is created by the hotplug/wifi config
//lib/wifi/mac80211.sh
scripts. Those scripts run after the wifi devices have been probed by the system, while the uci-defaults scripts run during the init.d process (S10boot).
There seems to be an inherent race condition between the two, so I guess I am doing it wrong. Is there a better place to put this config?
There is also an issue with the hotplug wifi config script being run for EACH wifi phy detected, and the script then configures ALL phys each time. So it has a race condition with itself! This doesnt seem to matter as it will create the same configuration a few times in a row.