network: track whether network is known

network_info gets a is_known flag that is used for the
GetOrderedNetworks tracking and to implement the KnownNetworks
interface - loading of the list of known networks on startup and
forgetting networks.
This commit is contained in:
Andrew Zaborowski 2016-06-17 00:54:14 +02:00 committed by Denis Kenzior
parent 9daf1f3fcf
commit 694c91db44
2 changed files with 58 additions and 2 deletions

View File

@ -141,6 +141,8 @@ bool network_connected(struct network *network)
if (err < 0)
return false;
network->info->is_known = true;
return true;
}
@ -161,7 +163,7 @@ static int network_find_rank_index(const struct network_info *info)
if (network == info)
return n;
if (network->seen_count)
if (network->is_known && network->seen_count)
n++;
}
@ -244,6 +246,9 @@ static void network_info_put(struct network_info *network)
if (--network->seen_count)
return;
if (network->is_known)
return;
l_queue_remove(networks, network);
network_info_free(network);
}
@ -742,12 +747,60 @@ void network_rank_update(struct network *network)
n = L_ARRAY_SIZE(rankmod_table) - 1;
rank = rankmod_table[n] * best_bss->rank + USHRT_MAX;
} else
} else if (network->info->is_known)
rank = best_bss->rank;
else
rank = (int) best_bss->rank - USHRT_MAX; /* Negative rank */
network->rank = rank;
}
bool network_info_add_known(const char *ssid, enum security security)
{
struct network_info *network;
int err;
network = l_new(struct network_info, 1);
strcpy(network->ssid, ssid);
network->type = security;
err = storage_network_get_mtime(security_to_str(security), ssid,
&network->connected_time);
if (err < 0) {
l_free(network);
return false;
}
network->is_known = true;
l_queue_insert(networks, network, timespec_compare, NULL);
return true;
}
bool network_info_forget_known(const char *ssid, enum security security)
{
struct network_info *network, search;
search.type = security;
strcpy(search.ssid, ssid);
network = l_queue_remove_if(networks, network_info_match, &search);
if (!network)
return false;
if (network->seen_count) {
memset(&network->connected_time, 0, sizeof(struct timespec));
network->is_known = false;
l_queue_push_tail(networks, network);
} else
network_info_free(network);
return true;
}
void network_info_foreach(network_info_foreach_func_t function,
void *user_data)
{

View File

@ -70,10 +70,13 @@ struct network_info {
struct timespec connected_time; /* Time last connected */
struct timespec seen_time; /* Time last seen */
int seen_count; /* Ref count for network.info */
bool is_known:1;
};
typedef void (*network_info_foreach_func_t)(const struct network_info *info,
void *user_data);
bool network_info_add_known(const char *ssid, enum security security);
bool network_info_forget_known(const char *ssid, enum security security);
void network_info_foreach(network_info_foreach_func_t function,
void *user_data);