nl80211: Separate channel noise fetch from scan result processing
This untangles the NL80211_CMD_GET_SURVEY handler loop from NL80211_CMD_GET_SCAN processing so that the per-channel noise information can be fetched with a common function to a local data structure that can then be easily used to update individual scan results (a single BSS) instead of having to go through a full set of scan results. This is a step towards optimizing scan result fetching without having to allocate memory for all entries at the same time. Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
parent
f0b6d1edfb
commit
e35e137298
1 changed files with 44 additions and 21 deletions
|
@ -20,6 +20,14 @@
|
||||||
#include "driver_nl80211.h"
|
#include "driver_nl80211.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_NL80211_NOISE_FREQS 50
|
||||||
|
|
||||||
|
struct nl80211_noise_info {
|
||||||
|
u32 freq[MAX_NL80211_NOISE_FREQS];
|
||||||
|
s8 noise[MAX_NL80211_NOISE_FREQS];
|
||||||
|
unsigned int count;
|
||||||
|
};
|
||||||
|
|
||||||
static int get_noise_for_scan_results(struct nl_msg *msg, void *arg)
|
static int get_noise_for_scan_results(struct nl_msg *msg, void *arg)
|
||||||
{
|
{
|
||||||
struct nlattr *tb[NL80211_ATTR_MAX + 1];
|
struct nlattr *tb[NL80211_ATTR_MAX + 1];
|
||||||
|
@ -29,9 +37,10 @@ static int get_noise_for_scan_results(struct nl_msg *msg, void *arg)
|
||||||
[NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
|
[NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
|
||||||
[NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
|
[NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
|
||||||
};
|
};
|
||||||
struct wpa_scan_results *scan_results = arg;
|
struct nl80211_noise_info *info = arg;
|
||||||
struct wpa_scan_res *scan_res;
|
|
||||||
size_t i;
|
if (info->count >= MAX_NL80211_NOISE_FREQS)
|
||||||
|
return NL_STOP;
|
||||||
|
|
||||||
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
|
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
|
||||||
genlmsg_attrlen(gnlh, 0), NULL);
|
genlmsg_attrlen(gnlh, 0), NULL);
|
||||||
|
@ -55,33 +64,24 @@ static int get_noise_for_scan_results(struct nl_msg *msg, void *arg)
|
||||||
if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
|
if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
|
||||||
return NL_SKIP;
|
return NL_SKIP;
|
||||||
|
|
||||||
for (i = 0; i < scan_results->num; ++i) {
|
info->freq[info->count] =
|
||||||
scan_res = scan_results->res[i];
|
nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
|
||||||
if (!scan_res)
|
info->noise[info->count] =
|
||||||
continue;
|
(s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
|
||||||
if ((int) nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
|
info->count++;
|
||||||
scan_res->freq)
|
|
||||||
continue;
|
|
||||||
if (!(scan_res->flags & WPA_SCAN_NOISE_INVALID))
|
|
||||||
continue;
|
|
||||||
scan_res->noise = (s8)
|
|
||||||
nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
|
|
||||||
scan_res->flags &= ~WPA_SCAN_NOISE_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NL_SKIP;
|
return NL_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int nl80211_get_noise_for_scan_results(
|
static int nl80211_get_noise_for_scan_results(
|
||||||
struct wpa_driver_nl80211_data *drv,
|
struct wpa_driver_nl80211_data *drv, struct nl80211_noise_info *info)
|
||||||
struct wpa_scan_results *scan_res)
|
|
||||||
{
|
{
|
||||||
struct nl_msg *msg;
|
struct nl_msg *msg;
|
||||||
|
|
||||||
|
os_memset(info, 0, sizeof(*info));
|
||||||
msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
|
msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
|
||||||
return send_and_recv_msgs(drv, msg, get_noise_for_scan_results,
|
return send_and_recv_msgs(drv, msg, get_noise_for_scan_results, info);
|
||||||
scan_res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -853,6 +853,21 @@ static void wpa_driver_nl80211_check_bss_status(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void nl80211_update_scan_res_noise(struct wpa_scan_res *res,
|
||||||
|
struct nl80211_noise_info *info)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; res && i < info->count; i++) {
|
||||||
|
if ((int) info->freq[i] != res->freq ||
|
||||||
|
!(res->flags & WPA_SCAN_NOISE_INVALID))
|
||||||
|
continue;
|
||||||
|
res->noise = info->noise[i];
|
||||||
|
res->flags &= ~WPA_SCAN_NOISE_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct wpa_scan_results *
|
static struct wpa_scan_results *
|
||||||
nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv)
|
nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv)
|
||||||
{
|
{
|
||||||
|
@ -874,9 +889,17 @@ nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv)
|
||||||
arg.res = res;
|
arg.res = res;
|
||||||
ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
|
ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
struct nl80211_noise_info info;
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu "
|
wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu "
|
||||||
"BSSes)", (unsigned long) res->num);
|
"BSSes)", (unsigned long) res->num);
|
||||||
nl80211_get_noise_for_scan_results(drv, res);
|
if (nl80211_get_noise_for_scan_results(drv, &info) == 0) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < res->num; ++i)
|
||||||
|
nl80211_update_scan_res_noise(res->res[i],
|
||||||
|
&info);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
|
wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
|
||||||
|
|
Loading…
Reference in a new issue