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 <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2018-09-13 00:02:50 -04:00 committed by waddlesplash
parent 4e5aaaa700
commit 45bc01d2f7
2 changed files with 31 additions and 1 deletions

View File

@ -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)

View File

@ -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);