@@ -1129,8 +1129,17 @@ bool network_update_known_frequencies(struct network *network)
return true;
}
+static bool match_addr(const void *a, const void *b)
+{
+ const struct scan_bss *bss = a;
+
+ return memcmp(bss->addr, b, 6) == 0;
+}
+
bool network_bss_add(struct network *network, struct scan_bss *bss)
{
+ l_queue_remove_if(network->bss_list, match_addr, bss->addr);
+
if (!l_queue_insert(network->bss_list, bss, scan_bss_rank_compare,
NULL))
return false;
@@ -1150,13 +1159,6 @@ bool network_bss_add(struct network *network, struct scan_bss *bss)
return true;
}
-static bool match_addr(const void *a, const void *b)
-{
- const struct scan_bss *bss = a;
-
- return memcmp(bss->addr, b, 6) == 0;
-}
-
/*
* Replaces an old scan_bss (if exists) in the bss list with a new bss object.
* Note this BSS is *not* freed and must be by the caller. scan_bss objects are
@@ -1188,6 +1190,33 @@ void network_bss_list_clear(struct network *network)
network->bss_list = l_queue_new();
}
+struct network_prune_data {
+ struct network *network;
+ struct l_queue *new_list;
+};
+
+static bool scan_bss_prune_missing(void *a, void *user_data)
+{
+ struct scan_bss *bss = a;
+ struct network_prune_data *data = user_data;
+
+ if (!l_queue_find(data->new_list, match_addr, bss->addr))
+ return true;
+
+ return false;
+}
+
+void network_bss_list_prune(struct network *network, struct l_queue *new_list)
+{
+ struct network_prune_data data;
+
+ data.network = network;
+ data.new_list = new_list;
+
+ l_queue_foreach_remove(network->bss_list,
+ scan_bss_prune_missing, &data);
+}
+
struct scan_bss *network_bss_list_pop(struct network *network)
{
return l_queue_pop_head(network->bss_list);
@@ -71,6 +71,8 @@ bool network_bss_add(struct network *network, struct scan_bss *bss);
bool network_bss_update(struct network *network, struct scan_bss *bss);
bool network_bss_list_isempty(struct network *network);
void network_bss_list_clear(struct network *network);
+void network_bss_list_prune(struct network *network, struct l_queue *new_list);
+
struct scan_bss *network_bss_list_pop(struct network *network);
struct scan_bss *network_bss_find_by_addr(struct network *network,
const uint8_t *addr);