Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions command/cmd_wifiscan.uc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (!ctx) {
}

const SCAN_FLAG_AP = (1<<2);
const CHANNEL_DWELL = 1000;
const frequency_list_2g = [ 2412, 2417, 2422, 2427, 2432, 2437, 2442,
2447, 2452, 2457, 2462, 2467, 2472, 2484 ];
const frequency_list_5g = { '3': [ 5180, 5260, 5500, 5580, 5660, 5745 ],
Expand Down Expand Up @@ -78,9 +79,7 @@ function scan_trigger(wdev, frequency, width) {
params.scan_frequencies = frequency;
}
else if (frequency && width) {
params.wiphy_freq = frequency;
params.center_freq1 = frequency + frequency_offset[width];
params.channel_width = frequency_width[width];
params.scan_frequencies = [ frequency ];
}

if (active)
Expand All @@ -105,9 +104,23 @@ function scan_trigger(wdev, frequency, width) {
warn("Scan aborted by kernel\n");
}

/* merge scan results by BSSID, the kernel expires them while we are still sweeping */
let bss_seen = {};

function collect_scan(dev) {
let res = nl.request(def.NL80211_CMD_GET_SCAN, def.NLM_F_DUMP, { dev });

for (let entry in res || [])
if (entry?.bss?.bssid)
bss_seen[entry.bss.bssid] = entry;
}

function trigger_scan_width(wdev, freqs, width) {
for (let freq in freqs)
for (let freq in freqs) {
scan_trigger(wdev, freq, width);
collect_scan(wdev);
sleep(CHANNEL_DWELL);
}
}

function phy_get(wdev) {
Expand Down Expand Up @@ -174,11 +187,15 @@ function wifi_scan() {

printf("scanning on phy%d\n", phy.wiphy);

bss_seen = {};

let freqs = phy_get_frequencies(phy);
if (length(intersect(freqs, frequency_list_2g)))
if (length(intersect(freqs, frequency_list_2g))) {
scan_trigger(iface.dev, frequency_list_2g);
collect_scan(iface.dev);
}

let ch_width = iface.channel_width;
let ch_width = '1';
if (frequency_width[bandwith])
ch_width = frequency_width[bandwith];
let freqs_5g = intersect(freqs, frequency_list_5g[ch_width]);
Expand All @@ -189,7 +206,8 @@ function wifi_scan() {
}
trigger_scan_width(iface.dev, freqs_5g, ch_width);
}
let res = nl.request(def.NL80211_CMD_GET_SCAN, def.NLM_F_DUMP, { dev: iface.dev });
collect_scan(iface.dev);
let res = values(bss_seen);
for (let bss in res) {
bss = bss.bss;
let res = {
Expand Down