scanner: parser-independent BSSID histogram in 10s heartbeat
Browse files at this commit5d9149d3eec486be33db53371a55019dfad2c8c5Parent: e3ca5481 changed file +33 -2
- src/scanner.rs +33 -2
src/scanner.rsmodified+33 -2
| @@ -220,6 +220,12 @@ struct ScanStats { | |||
| 220 | /// Beacons/probe-responses that ingested an AP row (created or already | 220 | /// Beacons/probe-responses that ingested an AP row (created or already |
| 221 | /// known — i.e. recognised AP-producing frames). | 221 | /// known — i.e. recognised AP-producing frames). |
| 222 | beacons_ap_ingested: u64, | 222 | beacons_ap_ingested: u64, |
| 223 | + /// Frames with beacon/probe-response FC byte, REGARDLESS of whether the | ||
| 224 | + /// IE walk later succeeded — the parser-independent RX witness. | ||
| 225 | + beacon_fc_rx: u64, | ||
| 226 | + /// addr3 histogram of beacon_fc frames: answers "are other BSSIDs even | ||
| 227 | + /// reaching the card" without trusting any parser. | ||
| 228 | + bssid_hist: std::collections::BTreeMap<crate::common::MacAddr, u64>, | ||
| 223 | } | 229 | } |
| 224 | 230 | ||
| 225 | /// Blocking channel-hop passive scan on an interface the caller already put | 231 | /// Blocking channel-hop passive scan on an interface the caller already put |
| @@ -270,6 +276,18 @@ pub fn run(cfg: ScannerConfig, tx: Sender<Event>, stop: Arc<AtomicBool>) -> Resu | |||
| 270 | let now = now_ms(); | 276 | let now = now_ms(); |
| 271 | if let Some((meta, frame)) = radiotap::strip(&buf[..n]) { | 277 | if let Some((meta, frame)) = radiotap::strip(&buf[..n]) { |
| 272 | stats.radiotap_strip_ok += 1; | 278 | stats.radiotap_strip_ok += 1; |
| 279 | + // Parser-independent witness: beacon (0x80) and | ||
| 280 | + // probe-response (0x50) frames carry the transmitter | ||
| 281 | + // BSSID at addr3 (bytes 16..22) before any IE parse. | ||
| 282 | + if frame.len() >= 24 && (frame[0] == 0x80 || frame[0] == 0x50) { | ||
| 283 | + stats.beacon_fc_rx += 1; | ||
| 284 | + let mut mac = [0u8; 6]; | ||
| 285 | + mac.copy_from_slice(&frame[16..22]); | ||
| 286 | + *stats | ||
| 287 | + .bssid_hist | ||
| 288 | + .entry(crate::common::MacAddr(mac)) | ||
| 289 | + .or_insert(0) += 1; | ||
| 290 | + } | ||
| 273 | if dot11::parse_beacon_or_probe(frame).is_some() { | 291 | if dot11::parse_beacon_or_probe(frame).is_some() { |
| 274 | stats.mgmt_80211_parsed += 1; | 292 | stats.mgmt_80211_parsed += 1; |
| 275 | stats.beacons_ap_ingested += 1; | 293 | stats.beacons_ap_ingested += 1; |
| @@ -306,12 +324,25 @@ pub fn run(cfg: ScannerConfig, tx: Sender<Event>, stop: Arc<AtomicBool>) -> Resu | |||
| 306 | // report says "only my own AP shows up". | 324 | // report says "only my own AP shows up". |
| 307 | if last_stats_log.elapsed() >= Duration::from_secs(10) { | 325 | if last_stats_log.elapsed() >= Duration::from_secs(10) { |
| 308 | last_stats_log = Instant::now(); | 326 | last_stats_log = Instant::now(); |
| 327 | + let top: String = { | ||
| 328 | + let mut v: Vec<(crate::common::MacAddr, u64)> = | ||
| 329 | + stats.bssid_hist.iter().map(|(m, c)| (*m, *c)).collect(); | ||
| 330 | + v.sort_unstable_by(|a, b| b.1.cmp(&a.1)); | ||
| 331 | + v.truncate(4); | ||
| 332 | + v.iter() | ||
| 333 | + .map(|(m, c)| format!("{m}({c})")) | ||
| 334 | + .collect::<Vec<_>>() | ||
| 335 | + .join(", ") | ||
| 336 | + }; | ||
| 309 | let _ = tx.send(Event::Log(format!( | 337 | let _ = tx.send(Event::Log(format!( |
| 310 | - "scan: {} rx frames, {} beacons -> {} APs live (ch {})", | 338 | + "scan: rx={} strip={} beaconfc={} beacons={} aps={} ch={} top=[{}]", |
| 311 | stats.raw_frames_received, | 339 | stats.raw_frames_received, |
| 340 | + stats.radiotap_strip_ok, | ||
| 341 | + stats.beacon_fc_rx, | ||
| 312 | stats.beacons_ap_ingested, | 342 | stats.beacons_ap_ingested, |
| 313 | scanner.aps.len(), | 343 | scanner.aps.len(), |
| 314 | - cur_ch | 344 | + cur_ch, |
| 345 | + top | ||
| 315 | ))); | 346 | ))); |
| 316 | } | 347 | } |
| 317 | 348 | ||