From patchwork Wed May 15 12:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13665185 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47EA66EB53 for ; Wed, 15 May 2024 12:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775748; cv=none; b=XJdhW0ECM6arBNGNS8PcFPZKs4UYfnw4YrASxq/YPFUcdtNlrifMDA0swERAfm2w6sl7knh+FVkWq0VAAWJeu65MNWtwSGk59qIECzd12MutKW9l2vhlbTsxWYHx9hyACg5bCAPlG6xhiwTsFPJmy6457Bq6oTE5B0QPWRzcrRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775748; c=relaxed/simple; bh=pgbCuaJSS9JWFrQpAd/Ot034FCwNFC+fNRkYN6kwFPg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=CpQLSklLtO/+bi8S2t1UuLxl5taEruMfdSc4vUEZDIPBRBhgcW6dSxqpQKi/5wXpCe17eRA9vxmBlzrfhX6FlUrR4u/jRkMH1StcydTS+0I7SqH2+ozqRUTasJ1CDtAKaOjjjRDUYFasw0VdUIKw5jy1txaAt4M1L9VDrgOOqSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AyeIZwaE; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AyeIZwaE" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-792bae4137bso646949285a.3 for ; Wed, 15 May 2024 05:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715775746; x=1716380546; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CQCG5OoDiAsKEOEh7vmRafPWObVvz/Xdd+/fPbFqSVc=; b=AyeIZwaEPvBvk+GQxz3CN2ME6o87XACm5vz9AtR7OjkQnZEKIJOjQIrmA6RGtTgzBv oUSJDqPS6wUGhcgSzxgPs5SpH4t5P7LDkW89NnLIoyKPlmXEtCD9BpkZsFNXo1CS68qJ 9nA48YmJeeeoJVOCxOR6QpVC9/LpsCltMvHCkqb2S9Wz5Sijz5jWauFbWSlpetdJq8Q1 1+tffca8bJWmATlTkDUPOk8/Y+NL0CTTCdkNJTM6/0EhDs/6ZaSv+fn3wZj/Dl6J1FcW NIV/6TsQM0Wub/XBwGfPdcnlSj9bV7ibRUJeBaRsdW8RcjedPVOWJZV4sXIBQrTpTt3x Q33w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715775746; x=1716380546; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CQCG5OoDiAsKEOEh7vmRafPWObVvz/Xdd+/fPbFqSVc=; b=QWIt6Ph3/OIdc1YZf7ayrgpl/sN3vMGGXuXyt88XfKp8+/WxW3zi2KBk3k4ZDy5zFm YVnSXu9RhDrixWDP7X66TRHruy3TBcg5ZwxVYldrU9a+QWEtFsrHnfMGx/zrKapVAjQO 25Z1WbyhA/EFp2pWEzVa+pjeugaRCSn8ZOqH/1XCr0NzbEGLC8Vz0XOntVToafPC/quc NNc1U57w2XryEPlvnQTR2mQ2gg9Gtbg7M16QwgVEZpSyTJVMp56PNbBnC9p2vN1iTyNd 8KxNXCCP6pAJrjAHfv0w/UZ3jhz8XqCUyYuDYTK3+IxHEb0q/b8P89dcpw1HO6DXZNfJ DdDw== X-Gm-Message-State: AOJu0YwCIKASqEDf57r4LPCvzxaA6kK1vC+LZVoBu5D7HuFVK8qPoTP7 psQrLKeNCTIAOSqMZuI6pnlk6dNQbLT3EZr7Zo6sXP9NBXtKaExeQ3v/0Lzh X-Google-Smtp-Source: AGHT+IEa0on9Rd+TtIZ+4bue+qulkoBaqROW+KLQXv4Y2zMo2CFyfWYLIzQ6T0Jxfp/3sUA6tu64Xw== X-Received: by 2002:a05:620a:200d:b0:792:bf4d:6e8b with SMTP id af79cd13be357-792c7577408mr1536465185a.14.1715775745674; Wed, 15 May 2024 05:22:25 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf2a11e8sm669380085a.58.2024.05.15.05.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 05:22:25 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 1/4] nl80211util: add ATTR_SURVEY_INFO to parse_attrs Date: Wed, 15 May 2024 05:22:18 -0700 Message-Id: <20240515122221.333230-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- src/nl80211util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nl80211util.c b/src/nl80211util.c index 3f9a43ac..15968d7d 100644 --- a/src/nl80211util.c +++ b/src/nl80211util.c @@ -181,6 +181,7 @@ static attr_handler handler_for_type(enum nl80211_attrs type) case NL80211_ATTR_FRAME: return extract_iovec; case NL80211_ATTR_WIPHY_BANDS: + case NL80211_ATTR_SURVEY_INFO: return extract_nested; case NL80211_ATTR_KEY_IDX: return extract_u8; From patchwork Wed May 15 12:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13665186 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E79874416 for ; Wed, 15 May 2024 12:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775750; cv=none; b=ut0L6d0AE+m+yiYShkB/sTWfuRHTwYi21DvhkxvGRFz3B5c8Y1rsNVwzpwt4lL4sIyLpgCGefFt8t5/oGl2W01iPIbPaLuWV81toCCXFeoRh9BoSaRzm3oW5moxRQC0ABY4/nDztyctSxBcXpoLK5DLzllt4Ijr14L+dLM6Rcds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775750; c=relaxed/simple; bh=Zbnbe3Xv0O+FWlOOeBBgSWiiHgRx2ROp9PPhEslwxgA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nQWCgug/FiKD3A1/+XxxirWDTjao6JRP/78vX0zWu48DNWy5lYMpY6D/TEb48bFr1NcEXCv1lkQ+kJfC4TMmXvK21ieSMg22keCU8RRzFbEI9dPRI3uShx3iObVHRq4Ye7gKSqddWtQuTzyKeN1HndlTP1W/lFNX6oRvskicOU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SEpvXJUg; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SEpvXJUg" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-792c34f891eso569414285a.1 for ; Wed, 15 May 2024 05:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715775747; x=1716380547; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eJ9cSCCjSZZTqPjshIpSrBvU31l14zNlm4J+f/AWweQ=; b=SEpvXJUg5KOxVPtkjIRTXBrMAPlkTvGlCA2zWUa15FgJA9Bc3bcJ0oG5UzzQ5chOnE o1bjpbsbwHQcACyd1DEVH7SSiZWCYd8I+SIcnFWWLDgCq8CnoYc5vFOWYvJmjiQtJ1tx NlUrnaFTh8bAlXprW17srVq9y2UpfzT4PhFt9crR/+enbVf0kYwOzILOzRYFwhQuLelv t8oTjrcioiWgBLW1dr0NHLv59ZwKB6ahXVJBelSEcddAng7NptXSkyr9beKOqw+RygLG 58/teYspaXIvyii5GZ8jt/ESFNxUKkygJ8cwZElKcbA4MSFFuh86+tD0rW3DvqCF0f/r 6OGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715775747; x=1716380547; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eJ9cSCCjSZZTqPjshIpSrBvU31l14zNlm4J+f/AWweQ=; b=izLCAGUTPWuIm11GetbK8uWcjAiiiHLa7rEGh5Q6dPtVJ13r18Xd0Kuv1rZAlYF6/3 aUbKUlHXCXSrrLC6rln390589aCtMYU3aaRyhZc2u9GVQfv5jIEd2bANlyC+hu/qdnCe bd6MVuhTtZNZ9JKBOj9JGx/efQfcCXENCZvZK1gfKkWkdqLjapgGfbjy/5TYknIz83KS rjgxJNPFEipRgkz9AVV31S4ukOLoFN7BD31/lfg0ztZuu0SXCfV0wX0iSOyl0y0P/C6r VVIlNewLu9I2clA3GYzzjggM97iLJeHV7b/2TjlYMxOw9YXJ/qaIWPlJfCiZmhZNBjX9 A4Fw== X-Gm-Message-State: AOJu0YwGiU4xsCKcH7cjNBM7E0cm0cLjYLmNU5ZJHdtbI6yL9jhr833g 4y/AmrinRnF+UvwSNb16pWmI74kkub7Rx1xfoN+tblEGiNdupz2PUmpunZAa X-Google-Smtp-Source: AGHT+IGoqqpXs8yCOT3CmJ8TG3aAxC/ZdLPIINcnTtBxeYwajU3AT42ARErf5nKbw7xvPPyzhS0yvA== X-Received: by 2002:a05:620a:4791:b0:792:8be8:1c67 with SMTP id af79cd13be357-792c7600e9fmr1835765785a.64.1715775746871; Wed, 15 May 2024 05:22:26 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf2a11e8sm669380085a.58.2024.05.15.05.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 05:22:26 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 2/4] scan: use GET_SURVEY for SNR calculation in ranking Date: Wed, 15 May 2024 05:22:19 -0700 Message-Id: <20240515122221.333230-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515122221.333230-1-prestwoj@gmail.com> References: <20240515122221.333230-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This issues a GET_SURVEY dump after scan results are available and populates the survey information within the scan results. Currently the only value obtained is the noise for a given frequency but the survey results structure was created if in the future more values need to be added. From the noise, the SNR can be calculated. This is then used in the ranking calculation to help lower BSS ranks that are on high noise channels. --- src/scan.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/scan.h | 2 + 2 files changed, 167 insertions(+), 7 deletions(-) diff --git a/src/scan.c b/src/scan.c index d3f0ad31..8699fe3e 100644 --- a/src/scan.c +++ b/src/scan.c @@ -132,6 +132,18 @@ struct scan_context { */ unsigned int get_fw_scan_cmd_id; struct wiphy *wiphy; + + unsigned int get_survey_cmd_id; +}; + +struct scan_survey { + int8_t noise; +}; + +struct scan_survey_results { + struct scan_survey survey_2_4[14]; + struct scan_survey survey_5[196]; + struct scan_survey survey_6[233]; }; struct scan_results { @@ -140,6 +152,9 @@ struct scan_results { uint64_t time_stamp; struct scan_request *sr; struct scan_freq_set *freqs; + struct scan_survey_results survey; + + bool survey_parsed : 1; }; static bool start_next_scan_request(struct wiphy_radio_work_item *item); @@ -217,6 +232,9 @@ static void scan_context_free(struct scan_context *sc) if (sc->get_fw_scan_cmd_id && nl80211) l_genl_family_cancel(nl80211, sc->get_fw_scan_cmd_id); + if (sc->get_survey_cmd_id && nl80211) + l_genl_family_cancel(nl80211, sc->get_survey_cmd_id); + wiphy_state_watch_remove(sc->wiphy, sc->wiphy_watch_id); l_free(sc); @@ -1663,6 +1681,8 @@ static void scan_bss_compute_rank(struct scan_bss *bss) { static const double RANK_HIGH_UTILIZATION_FACTOR = 0.8; static const double RANK_LOW_UTILIZATION_FACTOR = 1.2; + static const double RANK_HIGH_SNR_FACTOR = 1.2; + static const double RANK_LOW_SNR_FACTOR = 0.8; double rank; uint32_t irank; /* @@ -1689,6 +1709,13 @@ static void scan_bss_compute_rank(struct scan_bss *bss) else if (bss->utilization <= 63) rank *= RANK_LOW_UTILIZATION_FACTOR; + if (bss->have_snr) { + if (bss->snr <= 15) + rank *= RANK_LOW_SNR_FACTOR; + else if (bss->snr >= 30) + rank *= RANK_HIGH_SNR_FACTOR; + } + irank = rank; if (irank > USHRT_MAX) @@ -1824,6 +1851,41 @@ int scan_bss_rank_compare(const void *a, const void *b, void *user_data) return (bss->rank > new_bss->rank) ? 1 : -1; } +static bool scan_survey_get_snr(struct scan_results *results, + uint32_t freq, int32_t signal, + int8_t *snr) +{ + uint8_t channel; + enum band_freq band; + int8_t noise = 0; + + if (!results->survey_parsed) + return false; + + channel = band_freq_to_channel(freq, &band); + if (L_WARN_ON(!channel)) + return false; + + switch (band) { + case BAND_FREQ_2_4_GHZ: + noise = results->survey.survey_2_4[channel].noise; + break; + case BAND_FREQ_5_GHZ: + noise = results->survey.survey_5[channel].noise; + break; + case BAND_FREQ_6_GHZ: + noise = results->survey.survey_6[channel].noise; + break; + } + + if (noise) { + *snr = signal - noise; + return true; + } + + return false; +} + static void get_scan_callback(struct l_genl_msg *msg, void *user_data) { struct scan_results *results = user_data; @@ -1849,6 +1911,10 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data) bss->time_stamp = results->time_stamp - seen_ms_ago * L_USEC_PER_MSEC; + bss->have_snr = scan_survey_get_snr(results, bss->frequency, + bss->signal_strength / 100, + &bss->snr); + scan_bss_compute_rank(bss); l_queue_insert(results->bss_list, bss, scan_bss_rank_compare, NULL); } @@ -1925,11 +1991,104 @@ static void get_scan_done(void *user) l_free(results); } +static void get_survey_callback(struct l_genl_msg *msg, void *user_data) +{ + struct scan_results *results = user_data; + struct scan_survey_results *survey = &results->survey; + struct l_genl_attr attr; + uint16_t type, len; + const void *data; + const uint32_t *freq = NULL; + const int8_t *noise = NULL; + uint8_t channel; + enum band_freq band; + + if (nl80211_parse_attrs(msg, NL80211_ATTR_SURVEY_INFO, &attr, + NL80211_ATTR_UNSPEC) < 0) + return; + + while (l_genl_attr_next(&attr, &type, &len, &data)) { + switch (type) { + case NL80211_SURVEY_INFO_FREQUENCY: + if (len != 4) + return; + + freq = data; + break; + case NL80211_SURVEY_INFO_NOISE: + if (len != 1) + return; + + noise = data; + break; + } + } + + if (!freq || !noise) + return; + + channel = band_freq_to_channel(*freq, &band); + if (!channel) + return; + + /* At least one frequency was surveyed */ + results->survey_parsed = true; + + switch (band) { + case BAND_FREQ_2_4_GHZ: + survey->survey_2_4[channel].noise = *noise; + break; + case BAND_FREQ_5_GHZ: + survey->survey_5[channel].noise = *noise; + break; + case BAND_FREQ_6_GHZ: + survey->survey_6[channel].noise = *noise; + break; + } +} + +static void get_results(struct scan_results *results) +{ + struct l_genl_msg *scan_msg; + + scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8); + + l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8, + &results->sc->wdev_id); + results->sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg, + get_scan_callback, + results, get_scan_done); +} + +static void get_survey_done(void *user_data) +{ + struct scan_results *results = user_data; + struct scan_context *sc = results->sc; + + sc->get_survey_cmd_id = 0; + + get_results(results); +} + +static bool scan_survey(struct scan_results *results) +{ + struct scan_context *sc = results->sc; + struct l_genl_msg *survey_msg; + + survey_msg = l_genl_msg_new(NL80211_CMD_GET_SURVEY); + l_genl_msg_append_attr(survey_msg, NL80211_ATTR_WDEV, 8, + &sc->wdev_id); + sc->get_survey_cmd_id = l_genl_family_dump(nl80211, survey_msg, + get_survey_callback, results, + get_survey_done); + + return sc->get_survey_cmd_id != 0; +} + static void scan_get_results(struct scan_context *sc, struct scan_request *sr, struct scan_freq_set *freqs) { struct scan_results *results; - struct l_genl_msg *scan_msg; results = l_new(struct scan_results, 1); results->sc = sc; @@ -1938,13 +2097,12 @@ static void scan_get_results(struct scan_context *sc, struct scan_request *sr, results->bss_list = l_queue_new(); results->freqs = freqs; - scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8); + if (scan_survey(results)) + return; + else + l_warn("failed to start a scan survey"); - l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8, - &sc->wdev_id); - sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg, - get_scan_callback, - results, get_scan_done); + get_results(results); } static void scan_wiphy_watch(struct wiphy *wiphy, diff --git a/src/scan.h b/src/scan.h index 516b6152..0bfc9e47 100644 --- a/src/scan.h +++ b/src/scan.h @@ -75,6 +75,7 @@ struct scan_bss { uint64_t parent_tsf; uint8_t *wfd; /* Concatenated WFD IEs */ ssize_t wfd_size; /* Size of Concatenated WFD IEs */ + int8_t snr; bool mde_present : 1; bool cc_present : 1; bool cap_rm_neighbor_report : 1; @@ -89,6 +90,7 @@ struct scan_bss { bool dpp_configurator : 1; bool sae_pw_id_used : 1; bool sae_pw_id_exclusive : 1; + bool have_snr : 1; }; struct scan_parameters { From patchwork Wed May 15 12:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13665187 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86DC86EB53 for ; Wed, 15 May 2024 12:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775751; cv=none; b=ezO2Mt2AFS1W26WvBVUNq8pDvME4PBZGJzBCTlGMl8ejHPfHOw2z4YBGrJJS5xasqNphGoe5SML4dnh16Ndpg88z4J2lyJZnFB56h9MjmVHdBZNcv0L3K/TdHm4r4GIRYLjxdWmOAHVgVR6veJyF8NiZR62qHr8DxdvDEY+8Mtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775751; c=relaxed/simple; bh=ieXM6WVuAM5MH0/2baL+qD1UGTOSGRtxt4PJw+3zQBc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=odU46GPENg3/lELfq32lgWfGR5doX7pa3a4wB3cNplB6tk3LTqTdS8H0Mwhy41h8pGHEy04w/16t2c7Y2DjksG4Mywm4y3d9usaTy8e/UBN6uwwbv2Tj07BXMPcVfMABchPQOK7cv+VPFr7I8hYmeGlIr1EvIb+nGax7lLyeMOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c2grODuy; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c2grODuy" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-792b8d31702so427201485a.3 for ; Wed, 15 May 2024 05:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715775748; x=1716380548; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k79exwgCqVUrVnBuHOQy2LIeRnXzcjCZK4+8ra/2Vj0=; b=c2grODuydAR6gXVmEwUL/vu+Ia9coE05XZ1X2bFker3v5ik7f/qTU5YzPKWBQNQiw0 8Cf8E4BDS1yoIxZCClhqeMy0aB/LogJ+QJA5cpgsqxeca+WznoNUwpW548w1Culachy7 wZg5fkzfhBxTaRMo1aGbSxuFELjFrG8xpxNxIU1aTluvaMVfc81emqncVnbJTnSV/X8e WrULMfZLhKHyyEfDT8fqaYwyA7T6jm+Z1xNSwFzP5eU7O9a1uBz1pfm8HIQfKSBe66lM b6l9nUM+WCxTlPRE6Mjfh4e68LUS9syps+x+2aU5XYEJlOaUlfvPBxKRZWvkJLEWu6R5 ffyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715775748; x=1716380548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k79exwgCqVUrVnBuHOQy2LIeRnXzcjCZK4+8ra/2Vj0=; b=BfI4m+2knBwR5UFJST5xCjk+NNPi4CmButZAoF6E6DsBrPFlq53s53x244QGlTrRiT 4ykWm3L1wY5vCa3Z7zo3xZs4BKiH2cNmPQsPzH89rkUPIhlr+ytEL8rdMuns4cCxk5HC 7JxAkM4teTBBsXw90Ih4J0KuXNPbjg6/gyJBAPsFIl1mZf8QbXX1j0jMT0yzoX8nrCFw KsdbQYJbGSwOcoIcKk4IDzbfQDaKIH/YWVH9wPZNmfjGZn9uSSpIaBIXhFuY/mmwQwGZ p/zLRhsdXXG8akt2HuxBI25lGvM3Gi26KfmHAVFWWeyCZ1/0uEQ3M1mWdNcA3Mp2jQe3 dKpw== X-Gm-Message-State: AOJu0YyktOT6BOGdeZhCiXwkcZ1Y8jrcumv08fujldHZTETTvxgzR9Kh 15VsDspNKWKh/gSlGVuuiNm2OLjpgfn5ERZ8b4LpSxbMu+u5ipAc1fgE2hFp X-Google-Smtp-Source: AGHT+IGNAJ1JFcdWHpCW1Pc31A1CiRm9WIm5M7fcPd4WwVXUeyMw0iiLrfj2/OAWAU1SHd8/oF3Jew== X-Received: by 2002:a05:620a:f05:b0:793:29:7fe5 with SMTP id af79cd13be357-793002980a9mr23747885a.10.1715775748189; Wed, 15 May 2024 05:22:28 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf2a11e8sm669380085a.58.2024.05.15.05.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 05:22:27 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 3/4] scan: add flag if BSS load was advertised Date: Wed, 15 May 2024 05:22:20 -0700 Message-Id: <20240515122221.333230-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515122221.333230-1-prestwoj@gmail.com> References: <20240515122221.333230-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For ranking purposes the utilization was defaulted to a valid (127) which would not change the rank if that IE was not found in the scan results. Historically this was printed (debug) as part of the scan results but that was removed as it was somewhat confusing. i.e. did the AP _really_ have a utilization of 127? or was the IE not found? Since it is useful to see the BSS load if that is advertised add a flag to the scan_bss struct to indicate if the IE was present which can be checked. --- src/scan.c | 14 ++++++++------ src/scan.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/scan.c b/src/scan.c index 8699fe3e..555ab88e 100644 --- a/src/scan.c +++ b/src/scan.c @@ -1344,6 +1344,8 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, NULL) < 0) l_warn("Unable to parse BSS Load IE for " MAC, MAC_STR(bss->addr)); + else + bss->have_utilization = true; break; case IE_TYPE_VENDOR_SPECIFIC: @@ -1533,7 +1535,6 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr, size_t beacon_ies_len; bss = l_new(struct scan_bss, 1); - bss->utilization = 127; bss->source_frame = SCAN_BSS_BEACON; while (l_genl_attr_next(attr, &type, &len, &data)) { @@ -1704,10 +1705,12 @@ static void scan_bss_compute_rank(struct scan_bss *bss) rank *= RANK_6G_FACTOR; /* Rank loaded APs lower and lightly loaded APs higher */ - if (bss->utilization >= 192) - rank *= RANK_HIGH_UTILIZATION_FACTOR; - else if (bss->utilization <= 63) - rank *= RANK_LOW_UTILIZATION_FACTOR; + if (bss->have_utilization) { + if (bss->utilization >= 192) + rank *= RANK_HIGH_UTILIZATION_FACTOR; + else if (bss->utilization <= 63) + rank *= RANK_LOW_UTILIZATION_FACTOR; + } if (bss->have_snr) { if (bss->snr <= 15) @@ -1734,7 +1737,6 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu, bss = l_new(struct scan_bss, 1); memcpy(bss->addr, mpdu->address_2, 6); - bss->utilization = 127; bss->source_frame = SCAN_BSS_PROBE_REQ; bss->frequency = frequency; bss->signal_strength = rssi; diff --git a/src/scan.h b/src/scan.h index 0bfc9e47..06753b82 100644 --- a/src/scan.h +++ b/src/scan.h @@ -91,6 +91,7 @@ struct scan_bss { bool sae_pw_id_used : 1; bool sae_pw_id_exclusive : 1; bool have_snr : 1; + bool have_utilization : 1; }; struct scan_parameters { From patchwork Wed May 15 12:22:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13665188 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D62874E25 for ; Wed, 15 May 2024 12:22:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775753; cv=none; b=bqbKsNy0Eh9AvOtrNlqqdpR9ti9GPeTcFul793m6sTMC5ZyLZD/OHVdTuaUglnDtXFQE4EEMRo2e0FBEKLPiH0quy5VY45ft73stcXTOGoqOWeeIQ2Ntrn4uYOleMd2TOZUcVAc9PRDvf8jCidBw/qw2r8jXkjgcrQ07AQZU0l4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775753; c=relaxed/simple; bh=uoLh7ZThrih6ndfpJ1BfPHhyxIzr+KFOvg3V89yDoAw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=idsA5Bz1arNnTnRidl20VHon9KBQh1mG0P1TZABSFMobQw7SE56iEv++M9hjITU41j0Z748+LzDqhkzGes9oeDzH7JaNuC+RhOGlbM6VjzcTxI+MDsOyYtdyTPdiprSsel/Rsob7ULPokgYL1a7JlqV0uPC6nmn9LhbSVuBTbRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fw5BadAF; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fw5BadAF" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-792b8d30075so468434185a.1 for ; Wed, 15 May 2024 05:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715775749; x=1716380549; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pfKh5Zksqm4ttq/9eaP7c7Ayyv0YPlHKaWrWdMb3sGc=; b=fw5BadAFoc0+QyOQdjDBRSc0SYjGE32f8j7Md8tP8+EmF7JtxwTb2Ywyfgxy1tztHV bwpTMp4UDfLTb3y77dep4hnVxiACHi7DiL30ceqlxGLK+u0oFQ5y/Qt0f8GQ1PR6n4Q9 ffrqn42oiT9gkfOIdQtN9Eo43lnkkg2s8rvqo0s6NXtzh55ii/FgnzsmIYYV4rFmLFl7 Ce5BM7tSEvtgtLE4PZv6SWSIllepvDxDIV2PKBnlpHR0WWfqX7Lb161Gjn8a5LS3X6dG xYPFAlTWo0pyJ08ZW7Axw8+QbNWskOqGiXR+jUgQEb/ewWE15oHvdc8DLiQaFvPiSKcO zFpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715775749; x=1716380549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pfKh5Zksqm4ttq/9eaP7c7Ayyv0YPlHKaWrWdMb3sGc=; b=ptS1I2Z9CWKtb5+3kHqSRlR3kJIkweY/BQe7xlfiMIU+JYylQ7RP4tKCR2XQFIlgS5 DQH3sPNw5FJlqCIsszqaS8VBJvVxobBClH8oAbE6lRkFE5RKjIXmHYpB6UI8OIFNTGql TETtPZbbj8bHbvIfP8vU6CN317buvpqK9jZ+259PmdnwRsdfW1OE0cYIojP5vYPT6kfI 9UueH2p3kzFU9nBVLw9fOaSTyUvArWg7GlvFE31Zq4EUqfblky8no8t9nouQk2JR5w8W 1Ey2PEohad0tLO9pMtyMWNil2cnFqOWDLn8uxtG+/26Qurt6lOclrXRkHE8Lw7dUWgWH 9JGw== X-Gm-Message-State: AOJu0YxhDfDdfEDTU19x2XF5GwXsbffsrHR64W8xEC0c1f6zIf3zpAbC Pu6rLW53Tmd7cR5Npmp2ttY1lEAY71KTycqyGwnQGWlW4Q+/PlyIsgQsogXb X-Google-Smtp-Source: AGHT+IEL9Fwk7YyIO2cdSEGiHvAdxz60s/Vd3+PCUHYPZ1KMQWx1uMFeqLcf9nKqvVC0Apz7EBsLFQ== X-Received: by 2002:a05:620a:390d:b0:78d:6b42:6c17 with SMTP id af79cd13be357-792c7600fbfmr1969064585a.76.1715775749215; Wed, 15 May 2024 05:22:29 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf2a11e8sm669380085a.58.2024.05.15.05.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 05:22:28 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 4/4] station: refactor the printing of scan results, print SNR/load Date: Wed, 15 May 2024 05:22:21 -0700 Message-Id: <20240515122221.333230-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515122221.333230-1-prestwoj@gmail.com> References: <20240515122221.333230-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are a few values which are nice to see in debug logs. Namely the BSS load and SNR. Both of these values may not be available either due to the AP or local hardware limiations. Rather than print dummy values for these refactor the print so append the values only if they are set in the scan result. --- src/station.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/station.c b/src/station.c index 641068cc..2e5febee 100644 --- a/src/station.c +++ b/src/station.c @@ -402,6 +402,27 @@ static int bss_signal_strength_compare(const void *a, const void *b, void *user) return (bss->signal_strength > new_bss->signal_strength) ? 1 : -1; } +static void station_print_scan_bss(const struct scan_bss *bss) +{ + uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000); + char optional[64] = {0}; + char *ptr = optional; + + if (bss->have_snr) + ptr += sprintf(ptr, ", snr: %d", bss->snr); + + if (bss->have_utilization) + ptr += sprintf(ptr, ", load: %u/255", bss->utilization); + + l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, " + "strength: %i, data_rate: %u.%u%s", + util_address_to_string(bss->addr), + util_ssid_to_utf8(bss->ssid_len, bss->ssid), + bss->frequency, bss->rank, bss->signal_strength, + kbps100 / 10, kbps100 % 10, + optional); +} + /* * Returns the network object the BSS was added to or NULL if ignored. */ @@ -412,14 +433,8 @@ static struct network *station_add_seen_bss(struct station *station, enum security security; const char *path; char ssid[33]; - uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000); - l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, " - "strength: %i, data_rate: %u.%u", - util_address_to_string(bss->addr), - util_ssid_to_utf8(bss->ssid_len, bss->ssid), - bss->frequency, bss->rank, bss->signal_strength, - kbps100 / 10, kbps100 % 10); + station_print_scan_bss(bss); if (util_ssid_is_hidden(bss->ssid_len, bss->ssid)) { l_debug("BSS has hidden SSID"); @@ -2655,15 +2670,9 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list, while ((bss = l_queue_pop_head(bss_list))) { double rank; - uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000); struct roam_bss *rbss; - l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u," - " strength: %i, data_rate: %u.%u", - util_address_to_string(bss->addr), - util_ssid_to_utf8(bss->ssid_len, bss->ssid), - bss->frequency, bss->rank, bss->signal_strength, - kbps100 / 10, kbps100 % 10); + station_print_scan_bss(bss); /* Skip the BSS we are connected to */ if (!memcmp(bss->addr, station->connected_bss->addr, 6))