network: return boolean from network_rankmod

Since the rankmod value only makes sense for autoconnectable networks,
change network_rankmod to return an indication of whether the rankmod is
valid as a boolean instead of as a double, as discussed before.
This commit is contained in:
Andrew Zaborowski 2016-06-09 19:55:20 +02:00 committed by Denis Kenzior
parent e07b24e5d8
commit dae897854b
3 changed files with 9 additions and 8 deletions

View File

@ -207,7 +207,7 @@ static const double rankmod_table[] = {
0.2913406263, 0.2899228820, 0.2885345572, 0.2871745887,
};
double network_rankmod(uint32_t type, const char *ssid)
bool network_rankmod(const struct network *network, double *rankmod)
{
const struct l_queue_entry *entry;
int n;
@ -217,10 +217,10 @@ double network_rankmod(uint32_t type, const char *ssid)
entry = entry->next, n += 1) {
const struct network_info *info = entry->data;
if (info->type != type)
if (info->type != network->security)
continue;
if (strcmp(info->ssid, ssid))
if (strcmp(info->ssid, network->ssid))
continue;
nmax = L_ARRAY_SIZE(rankmod_table);
@ -228,10 +228,11 @@ double network_rankmod(uint32_t type, const char *ssid)
if (n >= nmax)
n = nmax - 1;
return rankmod_table[n];
*rankmod = rankmod_table[n];
return true;
}
return 0.0;
return false;
}
struct network *network_create(struct device *device,

View File

@ -28,7 +28,7 @@ struct network;
bool network_seen(struct network *network);
bool network_connected(struct network *network);
void network_disconnected(struct network *network);
double network_rankmod(uint32_t type, const char *ssid);
bool network_rankmod(const struct network *network, double *rankmod);
struct network *network_create(struct device *device,
uint8_t *ssid, uint8_t ssid_len,

View File

@ -1267,8 +1267,8 @@ static void process_bss(struct device *device, struct scan_bss *bss)
network_bss_add(network, bss);
rankmod = network_rankmod(security, network_get_ssid(network));
if (rankmod == 0.0)
/* See if network is autoconnectable (is a known network) */
if (!network_rankmod(network, &rankmod))
return;
entry = l_new(struct autoconnect_entry, 1);