diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-03-05 22:35:04 +0000 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-03-05 22:35:04 +0000 |
commit | 28954c917ff9ccc3cb6b79ce39b1d6c7841da13d (patch) | |
tree | 166eafef53933e8d30fdc704cf605319531b1134 /iw_scan.c | |
parent | 8f6b56b71ccee4eb800a5b1aa1edbbfb0a0cb6b4 (diff) | |
parent | 89de95a89953c20349a8c7c4684eba45feb34bf5 (diff) | |
download | wavemon-28954c917ff9ccc3cb6b79ce39b1d6c7841da13d.tar.gz |
Merge tag 'upstream/0.7.4'
Upstream version 0.7.4
Diffstat (limited to 'iw_scan.c')
-rw-r--r-- | iw_scan.c | 54 |
1 files changed, 47 insertions, 7 deletions
@@ -547,25 +547,65 @@ static void iw_extract_ie(struct iw_event *iwe, struct scan_result *sr) } /*----------------- End of code copied from iwlib -----------------------*/ +/* + * Ordering functions for scan results + */ +/* Order by ascending frequency. */ +static int cmp_chan(const struct scan_result *a, const struct scan_result *b) +{ + return a->freq < b->freq; +} + +static int cmp_chan_rev(const struct scan_result *a, const struct scan_result *b) +{ + return cmp_chan(b, a); +} + /* Order by descending signal strength. */ -extern int cmp_sig(const struct scan_result *a, const struct scan_result *b) +static int cmp_sig(const struct scan_result *a, const struct scan_result *b) { return a->qual.level - b->qual.level; } /* Order by ascending frequency first, then by descending signal strength. */ -extern int cmp_freq_sig(const struct scan_result *a, const struct scan_result *b) +static int cmp_chan_sig(const struct scan_result *a, const struct scan_result *b) +{ + return a->freq == b->freq ? cmp_sig(a, b) : cmp_chan(a, b); +} + +/* Show open access points first, ordered by mode. */ +static int cmp_open(const struct scan_result *a, const struct scan_result *b) +{ + return a->has_key > b->has_key; +} + +/* Sort (open) access points by descending signal strength. */ +static int cmp_open_sig(const struct scan_result *a, const struct scan_result *b) +{ + return a->has_key == b->has_key ? cmp_sig(a, b) : cmp_open(a, b); +} + +/* Sort (open) access points by ascending frequency, then by descending signal. */ +static int cmp_open_chan_sig(const struct scan_result *a, const struct scan_result *b) { - return a->freq == b->freq ? cmp_sig(a, b) : a->freq < b->freq; + return a->has_key == b->has_key ? cmp_chan_sig(a, b) : cmp_open(a, b); } -struct scan_result *get_scan_list(int skfd, const char *ifname, int we_version, - scan_cmp_func cmp_scan_result) +static int (*scan_cmp[])(const struct scan_result *, const struct scan_result *) = { + [SO_CHAN] = cmp_chan, + [SO_CHAN_REV] = cmp_chan_rev, + [SO_SIGNAL] = cmp_sig, + [SO_OPEN] = cmp_open, + [SO_CHAN_SIG] = cmp_chan_sig, + [SO_OPEN_SIG] = cmp_open_sig, + [SO_OPEN_CH_SI] = cmp_open_chan_sig +}; + +struct scan_result *get_scan_list(int skfd, const char *ifname, int we_version) { struct scan_result *head = NULL; struct iwreq wrq; int wait, waited = 0; - /* * Some drivers may return very large scan results, either because there * are many cells, or there are many large elements. Do not bother to @@ -649,7 +689,7 @@ struct scan_result *get_scan_list(int skfd, const char *ifname, int we_version, f = 0; - while (cur && cmp_scan_result(cur, new) > 0) + while (cur && scan_cmp[conf.scan_sort_order](cur, new) > 0) prev = &cur->next, cur = cur->next; *prev = new; |