From patchwork Tue Jun 2 00:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wang X-Patchwork-Id: 1301985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=neteaExR; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HtJecEMs; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bXWj60F1z9sTc for ; Tue, 2 Jun 2020 10:11:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y8j57Dws8QjmFvWFFtwOAZQSLh0EgfTCnMQKNCRix7M=; b=neteaExRopaMra r25mjcUy1kzHrYYDyjeEyVjSsItsbPViOtpB+SRtj+8r4zunaKz8j0h2TXGfSa5On7/OK+qMg+16i ov6MinmOsRPQUZCeoDy4XBeHuwb0hQSau5fCFSdlKazHlewViJ8qGEoSOet5afxB6fRqsuLASB0fd XNKWBI1IgUcpx7J+AS67Gdb0juLD4A0SOtK40/i/XaE39RPvqQ0RF4YfA9I7DekxS+nqV+Ljsir0z 6M+SJRooWGXk5Yq28uo634ihwvYaco+3rca9OI2mNjbnDY2oTPoqgrY8jnYVo8JCghXFzNDJFp93y n2RTkir09AboAdOm4f3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfuWD-0007Qb-NQ; Tue, 02 Jun 2020 00:11:01 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfuVs-0006ul-Kn for hostap@lists.infradead.org; Tue, 02 Jun 2020 00:10:42 +0000 Received: by mail-pg1-x541.google.com with SMTP id p21so4221697pgm.13 for ; Mon, 01 Jun 2020 17:10:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rhLQjqbr9PdnzsBRAJVQD8DumtYfTmfsQvIj2IjnHSM=; b=HtJecEMsg1FbauaG8ZHnekuKfR5CtOMQKosBFbe/HQM6YKlCUYAn2C5pzJWpOWRFBz se7Jgx63rFh5IOIZJmNhR+TKSmsCAkgA7+mrRAcFgzvH4HyFy031oeFY93aNNXVolO78 sJB6qMWrmQ5VvzhU6t280EI0TPXKigdkYBmCA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rhLQjqbr9PdnzsBRAJVQD8DumtYfTmfsQvIj2IjnHSM=; b=IWoxKGVZa9LFvKhMiWC8sRTDVpLJrtPYuJlcFr2J4YJCDiCsGNIOWamW5g1PN2X13l d87tQg45cyKVxfkEROWhn1MhfP8wqAjRvmfivddQoFUevezXMhgH2LqHDH7X+07bvYJp QO7MrfWffAe0rOpNV5+of9Of83UC89cBbbenmWqskGKHxDk76Hi8r1y+DAtDBDlANuSs kBwSjFZ89yc2RZsZ3P+Kqlt4ZiGgHQW8Z7Q3t/sXISk6gYskxmyxLOk1PpwllnZe1LRQ CBo0jssDaW2F5H9Ls1ZFT6Tb9dznkT9v1rwf8CzztQoPOTdTHCjn/x27DCPS3Hh+yUH/ wvPA== X-Gm-Message-State: AOAM5320XEjFVDcaDuXXRD3SzbOPs3oglLhQfjKlFYB9xRNQwd0Tvlvz GEk/UgYTgJss5n+HrN5u1U+aH1/Hm/s= X-Google-Smtp-Source: ABdhPJwWnxXUHUshVXBI78VCl2Ef8CA5H9Sb0hQbyXLIb/UYby8ctyswnrEo1wVjpuhm9Ai/Mpl6jQ== X-Received: by 2002:a65:5349:: with SMTP id w9mr21824679pgr.281.1591056639696; Mon, 01 Jun 2020 17:10:39 -0700 (PDT) Received: from localhost ([2620:15c:202:201:2b10:8627:31e7:c5ec]) by smtp.gmail.com with ESMTPSA id t14sm486502pju.42.2020.06.01.17.10.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Jun 2020 17:10:39 -0700 (PDT) From: Matthew Wang To: j@w1.fi Subject: [PATCH 4/6] wpas_module_tests: add need_to_roam module test Date: Mon, 1 Jun 2020 17:10:16 -0700 Message-Id: <20200602001018.83640-4-matthewmwang@chromium.org> X-Mailer: git-send-email 2.27.0.rc2.251.g90737beb825-goog In-Reply-To: <20200602001018.83640-1-matthewmwang@chromium.org> References: <20200602001018.83640-1-matthewmwang@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200601_171040_709654_58B5D196 X-CRM114-Status: GOOD ( 13.50 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hostap@lists.infradead.org, Matthew Wang Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Sanity check the wpa_supplicant_need_to_roam function to ensure that we're roaming (or not) in obvious situations. Signed-off-by: Matthew Wang --- wpa_supplicant/wpas_module_tests.c | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/wpa_supplicant/wpas_module_tests.c b/wpa_supplicant/wpas_module_tests.c index 4e37591be..c721c2514 100644 --- a/wpa_supplicant/wpas_module_tests.c +++ b/wpa_supplicant/wpas_module_tests.c @@ -12,6 +12,18 @@ #include "utils/module_tests.h" #include "wpa_supplicant_i.h" #include "blacklist.h" +#ifndef CONFIG_NO_ROAMING +#include "bss.h" +#include "config.h" +#include "scan.h" + + +enum roam_type { + ROAM_SAME_BAND, + ROAM_TO_5, + ROAM_TO_2, +}; +#endif /* CONFIG_NO_ROAMING */ static int wpas_blacklist_module_tests(void) @@ -70,6 +82,79 @@ fail: } +#ifndef CONFIG_NO_ROAMING +static int check_roam(struct wpa_supplicant *wpa_s, struct wpa_bss *curr, + struct wpa_bss *sel, enum roam_type type, int cur_level, + int sel_level, int cur_est, int sel_est) +{ + if (type == ROAM_TO_5) { + curr->freq = 2412; + sel->freq = 5180; + } else if (type == ROAM_TO_2) { + curr->freq = 5180; + sel->freq = 2412; + } else { + curr->freq = 2412; + sel->freq = 2417; + } + curr->level = cur_level; + sel->level = sel_level; + curr->snr = curr->level - (IS_5GHZ(curr->freq) ? + DEFAULT_NOISE_FLOOR_5GHZ : + DEFAULT_NOISE_FLOOR_2GHZ); + sel->snr = sel->level - (IS_5GHZ(sel->freq) ? + DEFAULT_NOISE_FLOOR_5GHZ : + DEFAULT_NOISE_FLOOR_2GHZ); + curr->est_throughput = cur_est; + sel->est_throughput = sel_est; + return wpa_supplicant_need_to_roam_within_ess(wpa_s, curr, sel); +} + + +static int wpas_need_to_roam_module_tests() +{ + wpa_printf(MSG_INFO, "need_to_roam module tests"); + struct wpa_supplicant wpa_s; + struct wpa_global global; + struct wpa_bss curr, sel; + struct wpa_ssid ssid; + struct wpa_driver_ops dummy_driver; + + /* Initialize both BSSes. */ + os_memset(&curr, 0, sizeof(curr)); + curr.bssid[0] = 1; + os_memset(&sel, 0, sizeof(sel)); + sel.bssid[0] = 2; + + /* Initialize the SSID. */ + os_memset(&ssid, 0, sizeof(ssid)); + ssid.bssid_set = 0; + + /* Initialize wpa_supplicant. We don't call *_init() functions because + * we'd like to do the bare minimum amount of setup necessary to test + * the wpa_supplicant_need_to_roam_within_ess() logic. + */ + os_memset(&wpa_s, 0, sizeof(wpa_s)); + os_memset(&dummy_driver, 0, sizeof(dummy_driver)); + os_memset(&global, 0, sizeof(global)); + os_memcpy(&wpa_s.ifname, "roam0", 5); + wpa_s.global = &global; + wpa_s.driver = &dummy_driver; + wpa_s.current_ssid = &ssid; + if (check_roam(&wpa_s, &curr, &sel, ROAM_TO_5, + -50, -80, 65000, 175500) || + !check_roam(&wpa_s, &curr, &sel, ROAM_TO_2, + -80, -50, 175500, 65000) || + check_roam(&wpa_s, &curr, &sel, ROAM_SAME_BAND, + -80, -80, 19500, 19500)) { + wpa_printf(MSG_ERROR, "need_to_roam module test failure"); + return -1; + } + return 0; +} +#endif /* CONFIG_NO_ROAMING */ + + int wpas_module_tests(void) { int ret = 0; @@ -79,6 +164,11 @@ int wpas_module_tests(void) if (wpas_blacklist_module_tests() < 0) ret = -1; +#ifndef CONFIG_NO_ROAMING + if (wpas_need_to_roam_module_tests() < 0) + ret = -1; +#endif /* CONFIG_NO_ROAMING */ + #ifdef CONFIG_WPS if (wps_module_tests() < 0) ret = -1;