koreader / lj-wpaclient

wpa_supplicant client library for LuaJIT
7 stars 3 forks source link

Scan taking a full 20 seconds on Kobo Aura #12

Open projectgus opened 2 hours ago

projectgus commented 2 hours ago

I was emboldened to try and figure out why my Kobo Aura always shows "Scanning for networks..." for a full 20 seconds each time it connects to Wi-Fi...

Uncommenting the print statements in wpaclient.lua (and adding two of my own log lines in koreader to confirm timing), I see:

10/10/24-21:38:37 DEBUG WpaSupplicant:getNetworkList scanning 
SCAN reply:     OK
3       1       1       0       CTRL-EVENT-BSS-ADDED 0 14:d8:64:02:1d:62
4       1       1       0       CTRL-EVENT-BSS-ADDED 1 d4:6e:0e:ad:c2:f1
5       1       1       1       CTRL-EVENT-SCAN-RESULTS
5       2       1       1       CTRL-EVENT-NETWORK-NOT-FOUND
10/10/24-21:38:57 DEBUG WpaSupplicant:getNetworkList scan done 

It seems like in the case of the Aura, this comment is wrong:

            -- If we get CTRL-EVENT-NETWORK-NOT-FOUND, it means no preferred networks were found during the scan.
            -- It also means *another* scan will be fired, so this invalidates CTRL-EVENT-SCAN-RESULTS,
            -- as the actual CTRL-EVENT-SCAN-STARTED may be delayed until our next iteration...
            -- It may take *multiple* scans, and events may be split across multiple reads...
            -- Which is why NetworkManager does another pass of waiting in case our heuristics fail...
            elseif ev.msg == "CTRL-EVENT-NETWORK-NOT-FOUND" then
                found_result = false
                expected_scans = expected_scans + 1

On the Aura, seems wpa_supplicant sends CTRL-EVENT-NETWORK-NOT-FOUND but doesn't start any new scan.

I note that the Aura is also one of the "older devices" that doesn't send CTRL-EVENT-SCAN-STARTED. (yay for ancient wpa_supplicant versions?)

Do you think it'd be reasonable to add a "quirk" here of "if wpa_supplicant didn't send CTRL-EVENT-SCAN-STARTED or "FAIL-BUSY*" as the first reply then assume it's old and cursed, so ignore CTRL-EVENT-NETWORK-NOT-FOUND?"

I'd be very happy to try and put something together and send a PR, but I don't have any devices to test with apart from two Auras...

projectgus commented 2 hours ago

no preferred networks were found during the scan

Poking around a bit more, I realised that wcli:listNetworks() is empty when the CTRL-EVENT-NETWORK-NOT-FOUND event comes back as Koreader hasn't added any networks yet.

So maybe better logic could be to call listNetworks() before scanning, and ignore CTRL-EVENT-NETWORK-NOT-FOUND if there are no networks configured at all? I don't know if that's a behaviour that's different on later wpa_supplicant or not?

(Again, happy to put together a PR if any of these sound like reasonable ideas to you.)

Frenzie commented 1 minute ago

That code was only changed recently btw: https://github.com/koreader/lj-wpaclient/pull/11

It's not strictly impossible that it worked fine/better with older devices; I have no idea really.