From d9a885438d5fe87d38eed3c17d3d42977e244aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 12 Oct 2026 20:39:07 +0300 Subject: [PATCH] hop by frequency: full TR-legal 5GHz + 6GHz PSC (phone hotspots on 6G were invisible) --- src/common.rs | 25 +++++++++++++++++++++++++ src/iface.rs | 15 +++++++++++++++ src/scanner.rs | 38 +++++++++++++++++++------------------- src/service.rs | 8 +++++++- 4 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/common.rs b/src/common.rs index 3ae92ce..5ece561 100644 --- a/src/common.rs +++ b/src/common.rs @@ -214,6 +214,31 @@ pub enum Event { pub const HOP_CHANNELS_24: &[u8] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; pub const HOP_CHANNELS_5: &[u8] = &[36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128]; +/// 2.4 GHz channel → carrier frequency (MHz). +pub fn freq_of_channel(ch: u8) -> Option { + match ch { + 1..=13 => Some(2407 + 5 * ch as u16), + 14 => Some(2484), + 36..=173 => Some(5000 + 5 * ch as u16), + _ => None, + } +} + +/// Default hop list as FREQUENCIES (MHz): every 2.4 GHz channel, the full +/// TR-legal 5 GHz span (incl. 132/136/140 which plain channel lists often +/// miss), and the 6 GHz PSC channels (6, 22, 38, 54, 70, 86 = +/// 5980/6060/6140/6220/6300/6380 MHz) — phone hotspots increasingly land +/// on 6 GHz and are invisible to channel-lists that omit it. +pub const HOP_FREQS_ALL: &[u16] = &[ + // 2.4 GHz ch 1..13 + 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, + // 5 GHz ch 36..64 and 100..140 + 5180, 5200, 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, + 5640, 5660, 5680, 5700, + // 6 GHz PSC + 5980, 6060, 6140, 6220, 6300, 6380, +]; + /// Commands the UI process sends to the privileged service /// (`--privileged-worker` child), serialized as one `serde_json` line each /// on the child's stdin. diff --git a/src/iface.rs b/src/iface.rs index 1167555..6992c3f 100644 --- a/src/iface.rs +++ b/src/iface.rs @@ -115,6 +115,21 @@ pub fn set_channel(ifname: &str, ch: u8) -> Result<()> { } } +/// Tune by carrier frequency — the only unambiguous way once 6 GHz enters +/// (6 GHz channel numbers collide with 2.4 GHz in `iw set channel`). +pub fn set_freq(ifname: &str, freq_mhz: u16) -> Result<()> { + let f = freq_mhz.to_string(); + match iw(&["dev", ifname, "set", "freq", &f]) { + Ok(_) => Ok(()), + Err(e) => { + std::thread::sleep(std::time::Duration::from_millis(50)); + iw(&["dev", ifname, "set", "freq", &f]) + .map(|_| ()) + .with_context(|| format!("set freq {f} on {ifname} after retry: {e:#}")) + } + } +} + /// Parse `iw dev info` for the current channel. /// Err if not determinable. pub fn current_channel(ifname: &str) -> Result { diff --git a/src/scanner.rs b/src/scanner.rs index edbc29d..c6cf04d 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -13,9 +13,7 @@ use std::time::{Duration, Instant}; use anyhow::{Context, Result}; use crossbeam_channel::Sender; -use crate::common::{ - AccessPoint, ClientInfo, Event, HOP_CHANNELS_24, HOP_CHANNELS_5, MacAddr, now_ms, -}; +use crate::common::{AccessPoint, ClientInfo, Event, HOP_FREQS_ALL, MacAddr, now_ms}; use crate::radiotap::RxMeta; use crate::rawsock::RawSocket; use crate::{dot11, iface, radiotap}; @@ -27,8 +25,9 @@ const CLIENT_EXPIRE_MS: u64 = 60_000; pub struct ScannerConfig { pub ifname: String, - /// Channels to hop; empty = all 2.4 + 5 GHz hop channels. - pub channels: Vec, + /// Carrier frequencies (MHz) to hop; empty = [`HOP_FREQS_ALL`] + /// (2.4 GHz, full TR-legal 5 GHz span, 6 GHz PSC). + pub freqs: Vec, /// Dwell per channel. pub dwell_ms: u32, /// RSSI below this blocks creation of new AP/client entries (updates to @@ -44,6 +43,9 @@ fn freq_to_channel(freq_mhz: u16) -> Option { 2484 => Some(14), // 5 GHz: ch = (freq - 5000) / 5. 5000..=5900 => Some(((freq_mhz - 5000) / 5) as u8), + // 6 GHz: ch = (freq - 5950) / 5 (collides numerically with 2.4 GHz; + // display-only usage here). + 5945..=6425 => Some(((freq_mhz - 5950) / 5) as u8), _ => None, } } @@ -235,18 +237,14 @@ pub fn run(cfg: ScannerConfig, tx: Sender, stop: Arc) -> Resu .with_context(|| format!("opening {} for scan", cfg.ifname))?; sock.set_timeout(cfg.dwell_ms).context("set_timeout")?; - let channels: Vec = if cfg.channels.is_empty() { - HOP_CHANNELS_24 - .iter() - .chain(HOP_CHANNELS_5.iter()) - .copied() - .collect() + let freqs: Vec = if cfg.freqs.is_empty() { + HOP_FREQS_ALL.to_vec() } else { - cfg.channels.clone() + cfg.freqs.clone() }; let _ = tx.send(Event::Log(format!( - "scanner: {} channels, {} ms dwell on {}", - channels.len(), + "scanner: {} freqs, {} ms dwell on {}", + freqs.len(), cfg.dwell_ms, cfg.ifname ))); @@ -258,12 +256,14 @@ pub fn run(cfg: ScannerConfig, tx: Sender, stop: Arc) -> Resu let mut last_stats_log = Instant::now(); while !stop.load(Ordering::Relaxed) { - let ch = channels[ch_idx]; - let cur_ch = ch; - ch_idx = (ch_idx + 1) % channels.len(); - if let Err(e) = iface::set_channel(&cfg.ifname, ch) { + let freq = freqs[ch_idx]; + // Display channel number (2.4/5 GHz exact; 6 GHz reported as its + // own channel number — cosmetic only). + let cur_ch = freq_to_channel(freq).map(|c| c as i32).unwrap_or(-1); + ch_idx = (ch_idx + 1) % freqs.len(); + if let Err(e) = iface::set_freq(&cfg.ifname, freq) { let _ = tx.send(Event::Log(format!( - "scanner: hop to ch {ch} failed: {e:#}" + "scanner: hop to {freq} MHz failed: {e:#}" ))); } diff --git a/src/service.rs b/src/service.rs index b197198..f4102e2 100644 --- a/src/service.rs +++ b/src/service.rs @@ -116,9 +116,15 @@ impl RadioService { self.mon_ifname = Some(mon_ifname.clone()); log(&self.tx, format!("monitor mode up on {mon_ifname} (was {ifname})")); + // Parked-diagnostic channel numbers (2.4/5 GHz) map to frequencies; + // empty = full default hop list incl. 6 GHz PSC. + let freqs: Vec = channels + .iter() + .filter_map(|&ch| crate::common::freq_of_channel(ch)) + .collect(); let cfg = scanner::ScannerConfig { ifname: mon_ifname, - channels: channels.to_vec(), // empty = full hop list + freqs, dwell_ms: 100, rssi_floor: -95, };