mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-27 10:52:47 +01:00
scan: Add initial BSS rank computation
This commit is contained in:
parent
05c83349c6
commit
1b4a3f19f3
53
src/scan.c
53
src/scan.c
@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <limits.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <ell/ell.h>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user