diff --git a/src/tweaks/menus.h b/src/tweaks/menus.h index bbf8cd33e4..d458ad87ed 100644 --- a/src/tweaks/menus.h +++ b/src/tweaks/menus.h @@ -92,7 +92,7 @@ bool _writeDateString(char *label_out) void menu_datetime(void *_) { if (!_menu_date_time._created) { - _menu_date_time = list_create(6, LIST_SMALL); + _menu_date_time = list_create(7, LIST_SMALL); strcpy(_menu_date_time.title, "Date and time"); list_addItem(&_menu_date_time, (ListItem){ @@ -125,6 +125,16 @@ void menu_datetime(void *_) " \n" "Ensures that time is synced before a game\n" "is launched."); + list_addItemWithInfoNote(&_menu_date_time, + (ListItem){ + .label = "Enable Wi-Fi temporarily", + .item_type = TOGGLE, + .disabled = !network_state.ntp, + .value = (int)network_state.force_wifi_on_startup, + .action = network_setNtpForceState}, + "Enables Wi-Fi temporarily at startup\n" + "to sync the time. It will be turned off\n" + "again after the sync (if it was off)."); list_addItemWithInfoNote(&_menu_date_time, (ListItem){ .label = "Get time zone via IP address", diff --git a/src/tweaks/network.h b/src/tweaks/network.h index 5e17e9acdd..a0fe5b4984 100644 --- a/src/tweaks/network.h +++ b/src/tweaks/network.h @@ -19,6 +19,7 @@ #include "utils/json.h" #include "utils/keystate.h" #include "utils/netinfo.h" +#include "utils/process.h" #include "./appstate.h" @@ -43,6 +44,7 @@ static struct network_s { bool keep_alive; bool vncserv; bool loaded; + bool force_wifi_on_startup; int vncfps; } network_state = { .vncfps = 20, @@ -61,6 +63,7 @@ void network_loadState(void) network_state.hotspot = config_flag_get(".hotspotState"); network_state.ntp = config_flag_get(".ntpState"); network_state.ntp_wait = config_flag_get(".ntpWait"); + network_state.force_wifi_on_startup = config_flag_get(".ntpForce"); network_state.auth_ftp = config_flag_get(".authftpState"); network_state.auth_http = config_flag_get(".authhttpState"); network_state.auth_ssh = config_flag_get(".authsshState"); @@ -288,6 +291,11 @@ void network_setNtpState(void *pt) all_changed = true; } +void network_setNtpForceState(void *pt) +{ + network_setState(&network_state.force_wifi_on_startup, ".ntpForce", ((ListItem *)pt)->value); +} + void network_setNtpWaitState(void *pt) { network_setState(&network_state.ntp_wait, ".ntpWait", ((ListItem *)pt)->value); diff --git a/static/build/.tmp_update/runtime.sh b/static/build/.tmp_update/runtime.sh index 19d82e0726..3fffc65d4f 100644 --- a/static/build/.tmp_update/runtime.sh +++ b/static/build/.tmp_update/runtime.sh @@ -851,12 +851,14 @@ start_networking() { } check_networking() { + if [ ! -f /tmp/network_changed ]; then + return + fi + if pgrep -f update_networking.sh; then log "update_networking already running" else - if [ -f /tmp/network_changed ]; then - rm /tmp/network_changed - fi + rm /tmp/network_changed $sysdir/script/network/update_networking.sh check fi } diff --git a/static/build/.tmp_update/script/network/update_networking.sh b/static/build/.tmp_update/script/network/update_networking.sh index b79341e582..fab0131744 100644 --- a/static/build/.tmp_update/script/network/update_networking.sh +++ b/static/build/.tmp_update/script/network/update_networking.sh @@ -33,7 +33,7 @@ main() { ;; authed) ${service}_authed & - store_state & + store_state & ;; *) print_usage @@ -73,10 +73,21 @@ main() { # Standard check from runtime for startup. check() { log "Network Checker: Update networking" - if wifi_enabled && [ "$is_booting" -eq 1 ]; then - bootScreen Boot "Waiting for network..." + local force_wifi_on_startup=$([ -f $sysdir/config/.ntpForce ] && echo 1 || echo 0) + local has_wifi=$(wifi_enabled && echo 1 || echo 0) + + if [ "$is_booting" -eq 1 ]; then + if [ "$has_wifi" -eq 0 ]; then + if [ "$force_wifi_on_startup" -eq 1 ]; then + bootScreen Boot "Turning on Wi-Fi..." + wifi_on + has_wifi=1 + fi + else + bootScreen Boot "Waiting for network..." + fi fi - + check_wifi check_ftpstate & check_sshstate & @@ -84,7 +95,7 @@ check() { check_httpstate & check_smbdstate & - if wifi_enabled && flag_enabled ntpWait && [ $is_booting -eq 1 ]; then + if [ "$has_wifi" -eq 1 ] && flag_enabled ntpWait && [ $is_booting -eq 1 ]; then bootScreen Boot "Syncing time..." check_ntpstate && bootScreen Boot "Time synced: $(date +"%H:%M")" || bootScreen Boot "Time sync failed" sleep 1 @@ -95,11 +106,15 @@ check() { if [ -f "$sysdir/.updateAvailable" ] && [ $is_booting -eq 1 ]; then bootScreen Boot "Update available!" sleep 1 - elif wifi_enabled && [ ! -f /tmp/update_checked ]; then + elif [ "$has_wifi" -eq 1 ] && [ ! -f /tmp/update_checked ]; then touch /tmp/update_checked $sysdir/script/ota_update.sh check & fi + if [ "$is_booting" -eq 1 ] && [ "$force_wifi_on_startup" -eq 1 ]; then + bootScreen Boot "Turning off Wi-Fi..." + wifi_off + fi } # Function to help disable and kill off all processes @@ -124,7 +139,7 @@ disable_all_services() { check_wifi() { # Fixes lockups entering some apps after enabling wifi (because wpa_supp/udhcpc are preloaded with libpadsp.so) libpadspblocker & - + if is_running hostapd; then return else @@ -136,25 +151,34 @@ check_wifi() { pkill -9 udhcpc rm /tmp/restart_wifi fi - log "Network Checker: Initializing wifi..." - /customer/app/axp_test wifion - sleep 2 - ifconfig wlan0 up - $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf - udhcpc -i wlan0 -s /etc/init.d/udhcpc.script & - iw dev wlan0 set power_save off + wifi_on fi else if [ ! -f "/tmp/dont_restart_wifi" ]; then store_state - pkill -9 wpa_supplicant - pkill -9 udhcpc - /customer/app/axp_test wifioff + wifi_off fi fi fi } +wifi_on() { + log "Network Checker: Turning on Wi-Fi..." + /customer/app/axp_test wifion + sleep 2 + ifconfig wlan0 up + $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf + udhcpc -i wlan0 -s /etc/init.d/udhcpc.script & + iw dev wlan0 set power_save off +} + +wifi_off() { + log "Network Checker: Turning off Wi-Fi..." + pkill -9 wpa_supplicant + pkill -9 udhcpc + /customer/app/axp_test wifioff +} + # Starts the samba daemon if the toggle is set to on check_smbdstate() { if flag_enabled smbdState; then @@ -568,7 +592,7 @@ init_json() { } # unhook libpadsp.so on the wifi servs -libpadspblocker() { +libpadspblocker() { wpa_pid=$(ps -e | grep "[w]pa_supplicant" | awk 'NR==1{print $1}') udhcpc_pid=$(ps -e | grep "[u]dhcpc" | awk 'NR==1{print $1}') if [ -n "$wpa_pid" ] && [ -n "$udhcpc_pid" ]; then @@ -576,8 +600,8 @@ libpadspblocker() { echo "Network Checker: $wpa_pid(WPA) and $udhcpc_pid(UDHCPC) found preloaded with libpadsp.so" unset LD_PRELOAD killall -9 wpa_supplicant - killall -9 udhcpc - $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf & + killall -9 udhcpc + $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf & udhcpc -i wlan0 -s /etc/init.d/udhcpc.script & echo "Network Checker: Removing libpadsp.so preload on wpa_supp/udhcpc" fi @@ -602,13 +626,12 @@ store_state() { service_key="$service_key \"$service\": \"0\"" fi done - + service_key="$service_key }" echo "$service_key" > "$jsonfile" } - -# Restore the network service state, don't use jq it's too slow and holds the UI thread until it returns +# Restore the network service state, don't use jq it's too slow and holds the UI thread until it returns # (you can't background this, you'll miss the checks for net servs as the flags won't be set) restore_state() { [ ! -f "$jsonfile" ] && return @@ -617,7 +640,7 @@ restore_state() { grep -E '"(httpState|ftpState|smbdState|sshState|authsshState|authftpState|authhttpState)":\s*"[01]"' "$jsonfile" | while IFS=":" read -r key value; do key=$(echo "$key" | tr -d ' "{}') value=$(echo "$value" | tr -d ' ",') - + if echo "$services" | grep -wq "$key"; then if [ "$value" = "1" ]; then enable_flag "$key" @@ -696,7 +719,7 @@ enable_flag() { disable_flag() { flag="$1" - mv "$sysdir/config/.$flag" "$sysdir/config/.$flag_" + mv "$sysdir/config/.$flag" "$sysdir/config/.$flag_" } is_running() { @@ -719,4 +742,3 @@ if [ -f $sysdir/config/.logging ]; then else main "$@" 2>&1 > /dev/null fi - diff --git a/static/configs/.tmp_update/config/.ntpForce_ b/static/configs/.tmp_update/config/.ntpForce_ new file mode 100644 index 0000000000..e69de29bb2 diff --git a/static/configs/.tmp_update/config/.ntpWait_ b/static/configs/.tmp_update/config/.ntpWait_ new file mode 100644 index 0000000000..e69de29bb2