From 1b4a3f19f3d49734451bd6e9195209b8ddb7d221 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 5 Jun 2015 18:18:55 -0500 Subject: [PATCH] scan: Add initial BSS rank computation --- src/scan.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/scan.h | 2 ++ 2 files changed, 55 insertions(+) diff --git a/src/scan.c b/src/scan.c index 4652e256..697884dd 100644 --- a/src/scan.c +++ b/src/scan.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -353,6 +354,55 @@ static struct scan_bss *scan_parse_result(struct l_genl_msg *msg, return bss; } +void scan_bss_compute_rank(struct scan_bss *bss) +{ + double RANK_RSNE_FACTOR = 1.2; + double RANK_WPA_FACTOR = 1.0; + double RANK_OPEN_FACTOR = 0.5; + double RANK_NO_PRIVACY_FACTOR = 0.5; + double RANK_5G_FACTOR = 1.1; + double rank; + uint32_t irank; + + /* + * Signal strength is in mBm (100 * dBm) and is negative. + * WiFi range is -0 to -100 dBm + */ + + /* Heavily slanted towards signal strength */ + rank = 10000 - bss->signal_strength; + + /* + * Prefer RSNE first, WPA second. Open networks are much less + * desirable. + */ + if (bss->rsne) + rank *= RANK_RSNE_FACTOR; + else if (bss->wpa) + rank *= RANK_WPA_FACTOR; + else + rank *= RANK_OPEN_FACTOR; + + /* We prefer networks with CAP PRIVACY */ + if (!(bss->capability & IE_BSS_CAP_PRIVACY)) + rank *= RANK_NO_PRIVACY_FACTOR; + + /* Prefer 5G networks over 2.4G */ + if (bss->frequency > 4000) + rank *= RANK_5G_FACTOR; + + /* TODO: Take BSS Load into consideration */ + + /* TODO: Take maximum supported rate into consideration */ + + irank = rank; + + if (irank > USHRT_MAX) + bss->rank = USHRT_MAX; + else + bss->rank = irank; +} + void scan_bss_free(struct scan_bss *bss) { l_free(bss->rsne); @@ -413,6 +463,9 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data) return; } + scan_bss_compute_rank(bss); + l_debug("computed rank: %u", bss->rank); + l_queue_push_tail(results->bss_list, bss); } diff --git a/src/scan.h b/src/scan.h index b96eda43..663d858c 100644 --- a/src/scan.h +++ b/src/scan.h @@ -40,6 +40,7 @@ struct scan_bss { uint8_t *wpa; uint8_t ssid[32]; uint8_t ssid_len; + uint16_t rank; }; void scan_start(struct l_genl_family *nl80211, uint32_t ifindex, @@ -54,6 +55,7 @@ void scan_sched_start(struct l_genl_family *nl80211, uint32_t ifindex, enum scan_ssid_security scan_get_ssid_security(enum ie_bss_capability bss_cap, const struct ie_rsn_info *info); void scan_bss_free(struct scan_bss *bss); +void scan_bss_compute_rank(struct scan_bss *bss); void bss_get_supported_ciphers(struct scan_bss *bss, uint16_t *pairwise_ciphers,