From 45bc01d2f71686b254d97ce04701c413d31cc76b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 13 Sep 2018 00:02:50 -0400 Subject: [PATCH] ifconfig & Network preferences: Actually trigger scans using BNetworkDevice. Fixes #12034, and a variety of other strange "no wireless networks appear" bugs that have plagued Haiku for years. Change-Id: I734cb8084e8a626b8e03511519609bf80c1559eb Reviewed-on: https://review.haiku-os.org/552 Reviewed-by: waddlesplash --- src/bin/network/ifconfig/ifconfig.cpp | 15 ++++++++++++++- src/preferences/network/InterfaceView.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/bin/network/ifconfig/ifconfig.cpp b/src/bin/network/ifconfig/ifconfig.cpp index 8bf9375a1a..99f21eaad4 100644 --- a/src/bin/network/ifconfig/ifconfig.cpp +++ b/src/bin/network/ifconfig/ifconfig.cpp @@ -281,6 +281,7 @@ configure_wireless(const char* name, char* const* args, int32 argCount) { enum { NONE, + SCAN, LIST, JOIN, LEAVE, @@ -290,7 +291,9 @@ configure_wireless(const char* name, char* const* args, int32 argCount) int controlOption = -1; int controlValue = -1; - if (!strcmp(args[0], "list") || !strcmp(args[0], "scan")) + if (!strcmp(args[0], "scan")) + mode = SCAN; + else if (!strcmp(args[0], "list")) mode = LIST; else if (!strcmp(args[0], "join")) mode = JOIN; @@ -324,6 +327,16 @@ configure_wireless(const char* name, char* const* args, int32 argCount) argCount--; switch (mode) { + case SCAN: + { + status_t status = device.Scan(true, true); + if (status != B_OK) { + fprintf(stderr, "%s: Scan on \"%s\" failed: %s\n", kProgramName, + name, strerror(status)); + exit(1); + } + // fall through + } case LIST: { // list wireless network(s) diff --git a/src/preferences/network/InterfaceView.cpp b/src/preferences/network/InterfaceView.cpp index 58ca818d0d..71e7c6901b 100644 --- a/src/preferences/network/InterfaceView.cpp +++ b/src/preferences/network/InterfaceView.cpp @@ -262,6 +262,23 @@ InterfaceView::_Update(bool updateWirelessNetworks) wireless_network network; int32 count = 0; + cookie = 0; + if ((fPulseCount % 15) == 0 + && device.GetNextNetwork(cookie, network) != B_OK) { + // We don't seem to know of any networks, and it's been long + // enough since the last scan, so trigger one to try and + // find some networks. + device.Scan(false, false); + + // We don't want to block for the full length of the scan, but + // 50ms is often more than enough to find at least one network, + // and the increase in perceived QoS to the user of not seeing + // "no wireless networks" if we can avoid it is great enough + // to merit such a wait. It's only just over ~4 vertical + // retraces, anyway. + snooze(50 * 1000); + } + cookie = 0; while (device.GetNextNetwork(cookie, network) == B_OK) { BMessage* message = new BMessage(kMsgJoinNetwork);