hop by frequency: full TR-legal 5GHz + 6GHz PSC (phone hotspots on 6G were invisible)
Browse files at this commitd9a885438d5fe87d38eed3c17d3d42977e244aacParent: fdf5c5a4 changed files +66 -20
- src/common.rs +25 -0
- src/iface.rs +15 -0
- src/scanner.rs +19 -19
- src/service.rs +7 -1
src/common.rsmodified+25 -0
| @@ -214,6 +214,31 @@ pub enum Event { | |||
| 214 | pub const HOP_CHANNELS_24: &[u8] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; | 214 | pub const HOP_CHANNELS_24: &[u8] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; |
| 215 | pub const HOP_CHANNELS_5: &[u8] = &[36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128]; | 215 | pub const HOP_CHANNELS_5: &[u8] = &[36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128]; |
| 216 | 216 | ||
| 217 | +/// 2.4 GHz channel → carrier frequency (MHz). | ||
| 218 | +pub fn freq_of_channel(ch: u8) -> Option<u16> { | ||
| 219 | + match ch { | ||
| 220 | + 1..=13 => Some(2407 + 5 * ch as u16), | ||
| 221 | + 14 => Some(2484), | ||
| 222 | + 36..=173 => Some(5000 + 5 * ch as u16), | ||
| 223 | + _ => None, | ||
| 224 | + } | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +/// Default hop list as FREQUENCIES (MHz): every 2.4 GHz channel, the full | ||
| 228 | +/// TR-legal 5 GHz span (incl. 132/136/140 which plain channel lists often | ||
| 229 | +/// miss), and the 6 GHz PSC channels (6, 22, 38, 54, 70, 86 = | ||
| 230 | +/// 5980/6060/6140/6220/6300/6380 MHz) — phone hotspots increasingly land | ||
| 231 | +/// on 6 GHz and are invisible to channel-lists that omit it. | ||
| 232 | +pub const HOP_FREQS_ALL: &[u16] = &[ | ||
| 233 | + // 2.4 GHz ch 1..13 | ||
| 234 | + 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, | ||
| 235 | + // 5 GHz ch 36..64 and 100..140 | ||
| 236 | + 5180, 5200, 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, | ||
| 237 | + 5640, 5660, 5680, 5700, | ||
| 238 | + // 6 GHz PSC | ||
| 239 | + 5980, 6060, 6140, 6220, 6300, 6380, | ||
| 240 | +]; | ||
| 241 | + | ||
| 217 | /// Commands the UI process sends to the privileged service | 242 | /// Commands the UI process sends to the privileged service |
| 218 | /// (`--privileged-worker` child), serialized as one `serde_json` line each | 243 | /// (`--privileged-worker` child), serialized as one `serde_json` line each |
| 219 | /// on the child's stdin. | 244 | /// on the child's stdin. |
src/iface.rsmodified+15 -0
| @@ -115,6 +115,21 @@ pub fn set_channel(ifname: &str, ch: u8) -> Result<()> { | |||
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | +/// Tune by carrier frequency — the only unambiguous way once 6 GHz enters | ||
| 119 | +/// (6 GHz channel numbers collide with 2.4 GHz in `iw set channel`). | ||
| 120 | +pub fn set_freq(ifname: &str, freq_mhz: u16) -> Result<()> { | ||
| 121 | + let f = freq_mhz.to_string(); | ||
| 122 | + match iw(&["dev", ifname, "set", "freq", &f]) { | ||
| 123 | + Ok(_) => Ok(()), | ||
| 124 | + Err(e) => { | ||
| 125 | + std::thread::sleep(std::time::Duration::from_millis(50)); | ||
| 126 | + iw(&["dev", ifname, "set", "freq", &f]) | ||
| 127 | + .map(|_| ()) | ||
| 128 | + .with_context(|| format!("set freq {f} on {ifname} after retry: {e:#}")) | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | +} | ||
| 132 | + | ||
| 118 | /// Parse `iw dev <ifname> info` for the current channel. | 133 | /// Parse `iw dev <ifname> info` for the current channel. |
| 119 | /// Err if not determinable. | 134 | /// Err if not determinable. |
| 120 | pub fn current_channel(ifname: &str) -> Result<u8> { | 135 | pub fn current_channel(ifname: &str) -> Result<u8> { |
src/scanner.rsmodified+19 -19
| @@ -13,9 +13,7 @@ use std::time::{Duration, Instant}; | |||
| 13 | use anyhow::{Context, Result}; | 13 | use anyhow::{Context, Result}; |
| 14 | use crossbeam_channel::Sender; | 14 | use crossbeam_channel::Sender; |
| 15 | 15 | ||
| 16 | -use crate::common::{ | 16 | +use crate::common::{AccessPoint, ClientInfo, Event, HOP_FREQS_ALL, MacAddr, now_ms}; |
| 17 | - AccessPoint, ClientInfo, Event, HOP_CHANNELS_24, HOP_CHANNELS_5, MacAddr, now_ms, | ||
| 18 | -}; | ||
| 19 | use crate::radiotap::RxMeta; | 17 | use crate::radiotap::RxMeta; |
| 20 | use crate::rawsock::RawSocket; | 18 | use crate::rawsock::RawSocket; |
| 21 | use crate::{dot11, iface, radiotap}; | 19 | use crate::{dot11, iface, radiotap}; |
| @@ -27,8 +25,9 @@ const CLIENT_EXPIRE_MS: u64 = 60_000; | |||
| 27 | 25 | ||
| 28 | pub struct ScannerConfig { | 26 | pub struct ScannerConfig { |
| 29 | pub ifname: String, | 27 | pub ifname: String, |
| 30 | - /// Channels to hop; empty = all 2.4 + 5 GHz hop channels. | 28 | + /// Carrier frequencies (MHz) to hop; empty = [`HOP_FREQS_ALL`] |
| 31 | - pub channels: Vec<u8>, | 29 | + /// (2.4 GHz, full TR-legal 5 GHz span, 6 GHz PSC). |
| 30 | + pub freqs: Vec<u16>, | ||
| 32 | /// Dwell per channel. | 31 | /// Dwell per channel. |
| 33 | pub dwell_ms: u32, | 32 | pub dwell_ms: u32, |
| 34 | /// RSSI below this blocks creation of new AP/client entries (updates to | 33 | /// RSSI below this blocks creation of new AP/client entries (updates to |
| @@ -44,6 +43,9 @@ fn freq_to_channel(freq_mhz: u16) -> Option<u8> { | |||
| 44 | 2484 => Some(14), | 43 | 2484 => Some(14), |
| 45 | // 5 GHz: ch = (freq - 5000) / 5. | 44 | // 5 GHz: ch = (freq - 5000) / 5. |
| 46 | 5000..=5900 => Some(((freq_mhz - 5000) / 5) as u8), | 45 | 5000..=5900 => Some(((freq_mhz - 5000) / 5) as u8), |
| 46 | + // 6 GHz: ch = (freq - 5950) / 5 (collides numerically with 2.4 GHz; | ||
| 47 | + // display-only usage here). | ||
| 48 | + 5945..=6425 => Some(((freq_mhz - 5950) / 5) as u8), | ||
| 47 | _ => None, | 49 | _ => None, |
| 48 | } | 50 | } |
| 49 | } | 51 | } |
| @@ -235,18 +237,14 @@ pub fn run(cfg: ScannerConfig, tx: Sender<Event>, stop: Arc<AtomicBool>) -> Resu | |||
| 235 | .with_context(|| format!("opening {} for scan", cfg.ifname))?; | 237 | .with_context(|| format!("opening {} for scan", cfg.ifname))?; |
| 236 | sock.set_timeout(cfg.dwell_ms).context("set_timeout")?; | 238 | sock.set_timeout(cfg.dwell_ms).context("set_timeout")?; |
| 237 | 239 | ||
| 238 | - let channels: Vec<u8> = if cfg.channels.is_empty() { | 240 | + let freqs: Vec<u16> = if cfg.freqs.is_empty() { |
| 239 | - HOP_CHANNELS_24 | 241 | + HOP_FREQS_ALL.to_vec() |
| 240 | - .iter() | ||
| 241 | - .chain(HOP_CHANNELS_5.iter()) | ||
| 242 | - .copied() | ||
| 243 | - .collect() | ||
| 244 | } else { | 242 | } else { |
| 245 | - cfg.channels.clone() | 243 | + cfg.freqs.clone() |
| 246 | }; | 244 | }; |
| 247 | let _ = tx.send(Event::Log(format!( | 245 | let _ = tx.send(Event::Log(format!( |
| 248 | - "scanner: {} channels, {} ms dwell on {}", | 246 | + "scanner: {} freqs, {} ms dwell on {}", |
| 249 | - channels.len(), | 247 | + freqs.len(), |
| 250 | cfg.dwell_ms, | 248 | cfg.dwell_ms, |
| 251 | cfg.ifname | 249 | cfg.ifname |
| 252 | ))); | 250 | ))); |
| @@ -258,12 +256,14 @@ pub fn run(cfg: ScannerConfig, tx: Sender<Event>, stop: Arc<AtomicBool>) -> Resu | |||
| 258 | let mut last_stats_log = Instant::now(); | 256 | let mut last_stats_log = Instant::now(); |
| 259 | 257 | ||
| 260 | while !stop.load(Ordering::Relaxed) { | 258 | while !stop.load(Ordering::Relaxed) { |
| 261 | - let ch = channels[ch_idx]; | 259 | + let freq = freqs[ch_idx]; |
| 262 | - let cur_ch = ch; | 260 | + // Display channel number (2.4/5 GHz exact; 6 GHz reported as its |
| 263 | - ch_idx = (ch_idx + 1) % channels.len(); | 261 | + // own channel number — cosmetic only). |
| 264 | - if let Err(e) = iface::set_channel(&cfg.ifname, ch) { | 262 | + let cur_ch = freq_to_channel(freq).map(|c| c as i32).unwrap_or(-1); |
| 263 | + ch_idx = (ch_idx + 1) % freqs.len(); | ||
| 264 | + if let Err(e) = iface::set_freq(&cfg.ifname, freq) { | ||
| 265 | let _ = tx.send(Event::Log(format!( | 265 | let _ = tx.send(Event::Log(format!( |
| 266 | - "scanner: hop to ch {ch} failed: {e:#}" | 266 | + "scanner: hop to {freq} MHz failed: {e:#}" |
| 267 | ))); | 267 | ))); |
| 268 | } | 268 | } |
| 269 | 269 | ||
src/service.rsmodified+7 -1
| @@ -116,9 +116,15 @@ impl RadioService { | |||
| 116 | self.mon_ifname = Some(mon_ifname.clone()); | 116 | self.mon_ifname = Some(mon_ifname.clone()); |
| 117 | log(&self.tx, format!("monitor mode up on {mon_ifname} (was {ifname})")); | 117 | log(&self.tx, format!("monitor mode up on {mon_ifname} (was {ifname})")); |
| 118 | 118 | ||
| 119 | + // Parked-diagnostic channel numbers (2.4/5 GHz) map to frequencies; | ||
| 120 | + // empty = full default hop list incl. 6 GHz PSC. | ||
| 121 | + let freqs: Vec<u16> = channels | ||
| 122 | + .iter() | ||
| 123 | + .filter_map(|&ch| crate::common::freq_of_channel(ch)) | ||
| 124 | + .collect(); | ||
| 119 | let cfg = scanner::ScannerConfig { | 125 | let cfg = scanner::ScannerConfig { |
| 120 | ifname: mon_ifname, | 126 | ifname: mon_ifname, |
| 121 | - channels: channels.to_vec(), // empty = full hop list | 127 | + freqs, |
| 122 | dwell_ms: 100, | 128 | dwell_ms: 100, |
| 123 | rssi_floor: -95, | 129 | rssi_floor: -95, |
| 124 | }; | 130 | }; |