Improved support for subnet colisions, and attempts to rejoin network.

This commit is contained in:
Ember
2026-03-03 14:32:28 -08:00
parent 120b6c887e
commit 8ab2bd0e5c
8 changed files with 650 additions and 117 deletions
+16
View File
@@ -238,6 +238,14 @@ struct TmobileArgs {
/// Web portal admin password.
#[arg(long)]
admin_password: String,
/// WiFi network name to connect to (enables WiFi client mode).
#[arg(long)]
wifi_ssid: Option<String>,
/// WiFi network password.
#[arg(long)]
wifi_password: Option<String>,
}
#[derive(Parser, Debug)]
@@ -285,6 +293,14 @@ struct WingtechArgs {
/// Web portal admin password.
#[arg(long)]
admin_password: String,
/// WiFi network name to connect to (enables WiFi client mode).
#[arg(long)]
wifi_ssid: Option<String>,
/// WiFi network password.
#[arg(long)]
wifi_password: Option<String>,
}
#[derive(Parser, Debug)]
+7 -1
View File
@@ -178,9 +178,15 @@ async fn setup_rayhunter(
)
.await?;
install_file(&mut adb_device, "/data/rayhunter/bin/wpa_cli", wpa_cli_bin).await?;
install_file(
&mut adb_device,
"/data/rayhunter/udhcpc-hook.sh",
include_bytes!("../../dist/scripts/udhcpc-hook.sh"),
)
.await?;
adb_at_syscmd(
&mut adb_device,
"chmod +x /data/rayhunter/bin/wpa_supplicant /data/rayhunter/bin/wpa_cli",
"chmod +x /data/rayhunter/bin/wpa_supplicant /data/rayhunter/bin/wpa_cli /data/rayhunter/udhcpc-hook.sh",
)
.await?;
}
+14 -4
View File
@@ -204,9 +204,12 @@ async fn wait_for_telnet(admin_ip: &str) -> Result<()> {
async fn check_disk_space(addr: SocketAddr, binary_size: usize) -> Result<()> {
// Use /data/rayhunter to resolve through symlink (may point to /cache/rayhunter-data)
let df_output =
telnet_send_command_with_output(addr, "df /data/rayhunter | tail -1 | awk '{print $4}'", false)
.await?;
let df_output = telnet_send_command_with_output(
addr,
"df /data/rayhunter | tail -1 | awk '{print $4}'",
false,
)
.await?;
let available_kb: usize = df_output
.lines()
.find(|l| l.trim().chars().all(|c| c.is_ascii_digit()) && !l.trim().is_empty())
@@ -278,6 +281,13 @@ async fn setup_rayhunter(
)
.await?;
telnet_send_file(addr, "/data/rayhunter/bin/wpa_cli", wpa_cli_bin, false).await?;
telnet_send_file(
addr,
"/data/rayhunter/udhcpc-hook.sh",
include_bytes!("../../dist/scripts/udhcpc-hook.sh"),
false,
)
.await?;
}
let wifi_enabled = wifi_ssid.is_some() && wifi_password.is_some();
@@ -317,7 +327,7 @@ async fn setup_rayhunter(
#[cfg(feature = "wifi-client")]
telnet_send_command(
addr,
"chmod +x /data/rayhunter/bin/wpa_supplicant /data/rayhunter/bin/wpa_cli",
"chmod +x /data/rayhunter/bin/wpa_supplicant /data/rayhunter/bin/wpa_cli /data/rayhunter/udhcpc-hook.sh",
"exit code 0",
false,
)
+16 -3
View File
@@ -18,6 +18,15 @@ pub async fn telnet_send_command_with_output(
addr: SocketAddr,
command: &str,
wait_for_prompt: bool,
) -> Result<String> {
telnet_send_command_with_timeout(addr, command, wait_for_prompt, Duration::from_secs(10)).await
}
async fn telnet_send_command_with_timeout(
addr: SocketAddr,
command: &str,
wait_for_prompt: bool,
command_timeout: Duration,
) -> Result<String> {
if command.contains('\n') {
bail!("multi-line commands are not allowed");
@@ -42,7 +51,7 @@ pub async fn telnet_send_command_with_output(
writer.write_all(format!("echo RAYHUNTER_'TELNET'_COMMAND_START; {command}; echo RAYHUNTER_'TELNET'_COMMAND_DONE\r\n").as_bytes()).await?;
let mut read_buf = Vec::new();
timeout(Duration::from_secs(10), async {
timeout(command_timeout, async {
loop {
let Ok(byte) = reader.read_u8().await else {
break;
@@ -61,7 +70,7 @@ pub async fn telnet_send_command_with_output(
}
})
.await
.context("command timed out after 10 seconds")?;
.with_context(|| format!("command timed out after {}s", command_timeout.as_secs()))?;
let string = String::from_utf8_lossy(&read_buf);
let start = string.rfind("RAYHUNTER_TELNET_COMMAND_START");
let end = string.rfind("RAYHUNTER_TELNET_COMMAND_DONE");
@@ -97,13 +106,17 @@ pub async fn telnet_send_file(
wait_for_prompt: bool,
) -> Result<()> {
print!("Sending file {filename} ... ");
// Allow 30s base + 2s per MB for the nc command to complete (covers slow WiFi links)
let transfer_timeout =
Duration::from_secs(30 + (payload.len() as u64 / (512 * 1024)).max(1) * 2);
let nc_output = {
let filename = filename.to_owned();
let handle = tokio::spawn(async move {
telnet_send_command_with_output(
telnet_send_command_with_timeout(
addr,
&format!("nc -l -p 8081 2>&1 >{filename}.tmp"),
wait_for_prompt,
transfer_timeout,
)
.await
});