2016-09-01 07:05:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-06-18 19:20:14 +00:00
|
|
|
# NOTE: Close any non-standard fds, so that it doesn't come back to bite us in the ass with USBMS (or sockets) later...
|
2020-08-25 00:00:59 +00:00
|
|
|
for fd in /proc/"$$"/fd/*; do
|
2024-06-18 19:20:14 +00:00
|
|
|
close_me="false"
|
2020-08-25 00:00:59 +00:00
|
|
|
fd_id="$(basename "${fd}")"
|
2024-06-18 19:20:14 +00:00
|
|
|
fd_path="$(readlink -f "${fd}")"
|
|
|
|
|
2020-08-25 00:00:59 +00:00
|
|
|
if [ -e "${fd}" ] && [ "${fd_id}" -gt 2 ]; then
|
2024-06-18 19:20:14 +00:00
|
|
|
if [ -S "${fd}" ]; then
|
|
|
|
# Close any and all sockets
|
|
|
|
# NOTE: Old busybox builds do something stupid when attempting to canonicalize pipes/sockets...
|
|
|
|
# (i.e., they'll spit out ${fd} as-is, losing any and all mention of a socket/pipe).
|
|
|
|
fd_path="$(readlink "${fd}")"
|
|
|
|
close_me="true"
|
|
|
|
elif [ -p "${fd}" ]; then
|
|
|
|
# We *might* be catching temporary pipes created by this very test, se we have to leave pipes alone...
|
|
|
|
# Although it would take extremely unlucky timing, as by the time we go through the top-level -e test,
|
|
|
|
# said temporary pipe is already gone, and as such we *should* never really enter this branch for temporary pipes ;).
|
|
|
|
fd_path="$(readlink "${fd}")"
|
|
|
|
close_me="false"
|
|
|
|
else
|
|
|
|
# NOTE: dash (meaning, in turn, busybox's ash) uses fd 10+ open to /dev/tty or $0 (w/ CLOEXEC)
|
|
|
|
# NOTE: The last fd != fd_path check is there to (potentially) whitelist non-regular files we might have failed to handle,
|
|
|
|
# it's designed to match the unhelpful result from old buysbox's readlink -f on non-regular files (c.f., previous notes).
|
|
|
|
if [ "${fd_path}" != "/dev/tty" ] && [ "${fd_path}" != "$(readlink -f "${0}")" ] && [ "${fd}" != "${fd_path}" ]; then
|
|
|
|
close_me="true"
|
|
|
|
else
|
|
|
|
close_me="false"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${fd_id}" -gt 2 ]; then
|
|
|
|
if [ "${close_me}" = "true" ]; then
|
2020-08-25 00:00:59 +00:00
|
|
|
eval "exec ${fd_id}>&-"
|
|
|
|
echo "[enable-wifi.sh] Closed fd ${fd_id} -> ${fd_path}"
|
2024-06-18 19:20:14 +00:00
|
|
|
else
|
|
|
|
# Try to log something more helpful when old busybox's readlink -f mangled it...
|
|
|
|
if [ "${fd}" = "${fd_path}" ]; then
|
|
|
|
fd_path="${fd_path} => $(readlink "${fd}")"
|
|
|
|
if [ ! -e "${fd}" ]; then
|
|
|
|
# Flag (potentially?) temporary items as such
|
|
|
|
fd_path="${fd_path} (temporary?)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "[enable-wifi.sh] Left fd ${fd_id} -> ${fd_path} open"
|
2020-08-25 00:00:59 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-09-28 19:31:52 +00:00
|
|
|
# Some platforms do *NOT* use sdio_wifi_pwr, even when it is physically there...
|
2023-08-01 18:26:02 +00:00
|
|
|
POWER_TOGGLE="module"
|
2022-09-28 19:31:52 +00:00
|
|
|
# We also want to choose the wpa_supplicant driver depending on the module...
|
|
|
|
WPA_SUPPLICANT_DRIVER="wext"
|
2023-08-01 18:26:02 +00:00
|
|
|
# And some platforms also put the modules in some funkier paths...
|
|
|
|
KMOD_PATH="/drivers/${PLATFORM}/wifi"
|
2022-09-28 19:31:52 +00:00
|
|
|
case "${WIFI_MODULE}" in
|
|
|
|
"moal")
|
2023-08-01 18:26:02 +00:00
|
|
|
POWER_TOGGLE="ntx_io"
|
2022-09-28 19:31:52 +00:00
|
|
|
WPA_SUPPLICANT_DRIVER="nl80211"
|
|
|
|
;;
|
2023-08-01 18:26:02 +00:00
|
|
|
"wlan_drv_gen4m")
|
|
|
|
POWER_TOGGLE="wmt"
|
|
|
|
WPA_SUPPLICANT_DRIVER="nl80211"
|
|
|
|
KMOD_PATH="/drivers/${PLATFORM}/mt66xx"
|
|
|
|
;;
|
2022-09-28 19:31:52 +00:00
|
|
|
esac
|
|
|
|
|
2023-08-01 18:26:02 +00:00
|
|
|
# Load the requested module if it isn't already
|
|
|
|
insmod_asneeded() {
|
|
|
|
kmod="${1}"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if ! grep -q "^${kmod} " "/proc/modules"; then
|
|
|
|
insmod "${KMOD_PATH}/${kmod}.ko" "${@}"
|
|
|
|
usleep 250000
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-28 19:31:52 +00:00
|
|
|
# Power up WiFi chip
|
2023-08-01 18:26:02 +00:00
|
|
|
case "${POWER_TOGGLE}" in
|
|
|
|
"ntx_io")
|
|
|
|
# 208 is CM_WIFI_CTRL
|
|
|
|
./luajit frontend/device/kobo/ntx_io.lua 208 1
|
|
|
|
;;
|
|
|
|
"wmt")
|
|
|
|
# NOTE: Unlike earlier platforms, it seems the WiFi modules are only loaded once, and never unloaded.
|
|
|
|
# So, just make sure they actually are loaded before we go on...
|
|
|
|
insmod_asneeded "wmt_drv"
|
|
|
|
insmod_asneeded "wmt_chrdev_wifi"
|
|
|
|
insmod_asneeded "wmt_cdev_bt"
|
|
|
|
insmod_asneeded "${WIFI_MODULE}"
|
2020-11-25 14:50:47 +00:00
|
|
|
|
2023-08-01 18:26:02 +00:00
|
|
|
# Black magic courtesy of wmt_dbg_func_ctrl @ (out of tree) modules/connectivity/wmt_mt66xx/common_main/linux/wmt_dbg.c
|
|
|
|
# Enable debug commands
|
|
|
|
echo "0xDB9DB9" >/proc/driver/wmt_dbg
|
|
|
|
# Disable the LPBK test
|
|
|
|
echo "7 9 0" >/proc/driver/wmt_dbg
|
|
|
|
# Nickel appears to sleep for ~1s
|
|
|
|
sleep 1
|
|
|
|
echo "0xDB9DB9" >/proc/driver/wmt_dbg
|
|
|
|
# Enable the LPBK test (this'll block for ~1.3s)
|
|
|
|
echo "7 9 1" >/proc/driver/wmt_dbg
|
|
|
|
# Finally, power on the chip
|
|
|
|
echo 1 >/dev/wmtWifi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if ! grep -q "^sdio_wifi_pwr " "/proc/modules"; then
|
|
|
|
if [ -e "${KMOD_PATH}/sdio_wifi_pwr.ko" ]; then
|
|
|
|
# Handle the shitty DVFS switcheroo...
|
|
|
|
if [ -n "${CPUFREQ_DVFS}" ]; then
|
|
|
|
echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
|
|
|
|
echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable"
|
|
|
|
fi
|
|
|
|
|
|
|
|
insmod "${KMOD_PATH}/sdio_wifi_pwr.ko"
|
|
|
|
else
|
|
|
|
# Poke the kernel via ioctl on platforms without the dedicated power module...
|
|
|
|
./luajit frontend/device/kobo/ntx_io.lua 208 1
|
|
|
|
fi
|
2022-09-28 19:31:52 +00:00
|
|
|
fi
|
2023-08-01 18:26:02 +00:00
|
|
|
;;
|
|
|
|
esac
|
2018-05-10 10:26:07 +00:00
|
|
|
# Moar sleep!
|
|
|
|
usleep 250000
|
2022-09-28 19:31:52 +00:00
|
|
|
|
|
|
|
# Load WiFi modules
|
2020-08-18 22:45:24 +00:00
|
|
|
# NOTE: Used to be exported in WIFI_MODULE_PATH before FW 4.23
|
2023-08-01 18:26:02 +00:00
|
|
|
if ! grep -q "^${WIFI_MODULE} " "/proc/modules"; then
|
2021-08-09 18:56:00 +00:00
|
|
|
# Set the Wi-Fi regulatory domain properly if necessary...
|
|
|
|
WIFI_COUNTRY_CODE_PARM=""
|
|
|
|
if grep -q "^WifiRegulatoryDomain=" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf"; then
|
|
|
|
WIFI_COUNTRY_CODE="$(grep "^WifiRegulatoryDomain=" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf" | cut -d '=' -f2)"
|
|
|
|
|
|
|
|
case "${WIFI_MODULE}" in
|
|
|
|
"8821cs")
|
|
|
|
WIFI_COUNTRY_CODE_PARM="rtw_country_code=${WIFI_COUNTRY_CODE}"
|
|
|
|
;;
|
2022-09-28 19:31:52 +00:00
|
|
|
"moal")
|
|
|
|
WIFI_COUNTRY_CODE_PARM="reg_alpha2=${WIFI_COUNTRY_CODE}"
|
|
|
|
;;
|
2021-08-09 18:56:00 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2022-09-28 19:31:52 +00:00
|
|
|
VENDOR_WIFI_PARM=""
|
|
|
|
case "${WIFI_MODULE}" in
|
|
|
|
"moal")
|
|
|
|
# NXP's driver for the Marvell 88W8987 RF SoC needs to be told what to choose between client, AP & WiFi DIRECT mode.
|
|
|
|
VENDOR_WIFI_PARM="mod_para=nxp/wifi_mod_para_sd8987.conf"
|
|
|
|
|
|
|
|
# And, of course, it requires a submodule...
|
|
|
|
WIFI_DEP_MOD="mlan"
|
2023-08-01 18:26:02 +00:00
|
|
|
insmod "${KMOD_PATH}/${WIFI_DEP_MOD}.ko"
|
2022-09-28 19:31:52 +00:00
|
|
|
# NOTE: Nickel sleeps for two whole seconds after each module loading.
|
|
|
|
# Let's try our usual timing instead...
|
|
|
|
usleep 250000
|
|
|
|
;;
|
2023-08-01 18:26:02 +00:00
|
|
|
"wlan_drv_gen4m")
|
|
|
|
# Nothing to do here, we only load the modules once, so we should never enter this branch.
|
|
|
|
;;
|
2022-09-28 19:31:52 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
WIFI_PARM=""
|
|
|
|
if [ -n "${WIFI_COUNTRY_CODE_PARM}" ]; then
|
|
|
|
if [ -n "${WIFI_PARM}" ]; then
|
|
|
|
WIFI_PARM="${WIFI_PARM} ${WIFI_COUNTRY_CODE_PARM}"
|
|
|
|
else
|
|
|
|
WIFI_PARM="${WIFI_COUNTRY_CODE_PARM}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "${VENDOR_WIFI_PARM}" ]; then
|
|
|
|
if [ -n "${WIFI_PARM}" ]; then
|
|
|
|
WIFI_PARM="${WIFI_PARM} ${VENDOR_WIFI_PARM}"
|
|
|
|
else
|
|
|
|
WIFI_PARM="${VENDOR_WIFI_PARM}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-08-01 18:26:02 +00:00
|
|
|
if [ -e "${KMOD_PATH}/${WIFI_MODULE}.ko" ]; then
|
2022-09-28 19:31:52 +00:00
|
|
|
if [ -n "${WIFI_PARM}" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
2023-08-01 18:26:02 +00:00
|
|
|
insmod "${KMOD_PATH}/${WIFI_MODULE}.ko" ${WIFI_PARM}
|
2021-08-14 15:28:26 +00:00
|
|
|
else
|
2023-08-01 18:26:02 +00:00
|
|
|
insmod "${KMOD_PATH}/${WIFI_MODULE}.ko"
|
2021-08-14 15:28:26 +00:00
|
|
|
fi
|
2021-07-21 16:12:58 +00:00
|
|
|
elif [ -e "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ]; then
|
|
|
|
# NOTE: Modules are unsorted on Mk. 8
|
2022-09-28 19:31:52 +00:00
|
|
|
if [ -n "${WIFI_PARM}" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ${WIFI_PARM}
|
2021-08-14 15:28:26 +00:00
|
|
|
else
|
|
|
|
insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko"
|
|
|
|
fi
|
2021-07-21 16:12:58 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-09-28 19:31:52 +00:00
|
|
|
|
2018-04-18 07:09:58 +00:00
|
|
|
# Race-y as hell, don't try to optimize this!
|
2022-09-28 19:31:52 +00:00
|
|
|
# NOTE: We're after a module insert, meaning Nickel may sleep for two whole seconds here.
|
|
|
|
case "${WIFI_MODULE}" in
|
|
|
|
"moal")
|
|
|
|
# NOTE: Bringup may be genuinely slower than usual with this chip, so, mimic Nickel's sleep patterns.
|
|
|
|
sleep 2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sleep 1
|
|
|
|
;;
|
|
|
|
esac
|
2016-09-01 07:05:40 +00:00
|
|
|
|
2022-09-28 19:31:52 +00:00
|
|
|
# Bring the network interface up & setup WiFi
|
2018-05-01 12:49:37 +00:00
|
|
|
ifconfig "${INTERFACE}" up
|
2021-07-21 16:12:58 +00:00
|
|
|
[ "${WIFI_MODULE}" = "dhd" ] && wlarm_le -i "${INTERFACE}" up
|
2016-09-01 07:05:40 +00:00
|
|
|
|
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
|
|
|
pkill -0 wpa_supplicant ||
|
2023-07-16 01:51:57 +00:00
|
|
|
wpa_supplicant -D "${WPA_SUPPLICANT_DRIVER}" -s -i "${INTERFACE}" -c /etc/wpa_supplicant/wpa_supplicant.conf -C /var/run/wpa_supplicant -B
|