Sorting netlink scan result by signal strength 39/234739/1
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 28 May 2020 08:13:17 +0000 (17:13 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 28 May 2020 08:13:22 +0000 (17:13 +0900)
Change-Id: I616fe6902a9ab906d2ef9b9fd052d8b19de84a09

src/wifi-netlink-scan.c

index c4ebca873d09ca7f80a8352d4636b90b77f53461..6ca6910d84afd9679a09026beae59c30dada99f5 100755 (executable)
 
 static GSList *bss_info_list = NULL;
 
+static gint __netconfig_compare_bss_by_rssi(gconstpointer a, gconstpointer b)
+{
+       struct bss_scan_info_t *entry_a = (struct bss_scan_info_t *) a;
+       struct bss_scan_info_t *entry_b = (struct bss_scan_info_t *) b;
+
+       if (entry_a->signal > entry_b->signal)
+               return -1;
+
+       if (entry_a->signal < entry_b->signal)
+               return 1;
+
+       return 0;
+}
+
 void __netconfig_notify_netlink_scan_done(void)
 {
        GVariantBuilder *builder = NULL;
@@ -48,6 +62,8 @@ void __netconfig_notify_netlink_scan_done(void)
        const char *prop_sec = "security";
        const char *prop_enc = "encryption";
 
+       bss_info_list = g_slist_sort(bss_info_list, __netconfig_compare_bss_by_rssi);
+
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        for (list = bss_info_list; list != NULL; list = list->next) {
                struct bss_scan_info_t *bss_info = (struct bss_scan_info_t *)list->data;