From patchwork Wed Jan 24 13:39:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13529248 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (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 962C9199BA for ; Wed, 24 Jan 2024 13:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103610; cv=none; b=tOLTyVpkRofAuBa4MR24f+c1kA7IxmXi8jFZhRiNRj5gPTQnCYwbYuGRA2CsnkRJRVMDit2/qIa68EEhyVxPShT+81kcZ6f91VI3x7MKhUEbR+COg/jUK0jVC5d1uqddutH+71k/9bNg7wugmP4/+aJf4RiWO2EHxyn0uifzkiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103610; c=relaxed/simple; bh=24D0PZsLFp59/l8YDmrcqW7GUUDopAe9DjMqaRG7X2s=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MKFgZX4WDS8Y8baWNlCLJBRqNRBZYgDnqtXA2LYeSdw0dvqHIsd0G/EBaL8nyzyyZ2DjoRNz3DkPE7VY/QEO15WBlUnFukm9COOOUAaTGNnpE1u5BF5G8azDlCG4FA879RW067iRA+NDAPOcEp/ENdcO+SUOifqZrOdW2de6bTM= 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=glyMnatJ; arc=none smtp.client-ip=209.85.128.173 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="glyMnatJ" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6029e069e08so6184237b3.0 for ; Wed, 24 Jan 2024 05:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706103607; x=1706708407; 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=95FKrAx90CxilkJ/M6gv4d89ixqRa0ufMbtb7PAA2WI=; b=glyMnatJjNnKr0yoY+V//S5tVIRNQlLro/wd6crK4x9GHDC/Q3/OrfXjvF7eHmDwX0 hgFMuCQgsc+915aFO1XlezlL4Yopy8v5zq8GsCyaeNOBFzgYX32vQNB0LDloAHK8vtr2 V0bvPG1EBoX+fshU+QPNjyt9MK5EsIpKi8bKRS0FiB0u5M1Bkm9vnfWoo7Hziezm9Idy fCA2Cz3d7LSoKO+CLzXTHGDUte56NvsgEce7jGo2/d7+JnNgwduwonxFs036ijY6bNnp l4zO3FO+/KysQDT4ILZAuYPb0fZkczsL7bZGeBNN+NubyS3fyJvqabkXKb39chqVx0lk pgDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706103607; x=1706708407; 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=95FKrAx90CxilkJ/M6gv4d89ixqRa0ufMbtb7PAA2WI=; b=iXQZhfy6v69xkNPMarKjhffzNARQ/LlGgnbVS7flQSoJ0k5R7JZK+vPLPTcIFBSHuv VvtuglJIGrwBg7Mqo3WRcn/7rib3GZuRtFbSxTjDveSjjbyCTmWUOp7tPzYGsaybLYmK pm/Gt+MexwtM+v+evpKbTkWRuQ9+IQoTI+Cbjc3A2mEdbGADOl1ydjM8Wvq2rdCI2NwU jbVzTggjo+0Rf+8orP3bJnZevt7fxgJlBNN0ZUFn8xK6KP5MFaa+cLYBpSTqCXFEDbku ABOEgQ5KL43OHhKCjVlb/+iJYWJAOWCRnyoC/j+iQcscpMIjz9o7HVyZLY87aArZXcvQ f52w== X-Gm-Message-State: AOJu0YyfoKZ9tUUhutRZ9ighssE3k30pcKXLBXOOgUsiswvKeXPwDlqp gcM2M3MBTokyWvXp17waHUMq1vN0DSBEe9ZlHrROqP7+0XriwAqHK/ppqLXldyg= X-Google-Smtp-Source: AGHT+IFFtOGbwocTyk+5xqrQbT1OzfVpB26cpCurlKVptA9IzLzbkEfsh5irosgxHwyJ205vJLnSdA== X-Received: by 2002:a05:6902:514:b0:dc2:2fa0:aad8 with SMTP id x20-20020a056902051400b00dc22fa0aad8mr604856ybs.106.1706103607256; Wed, 24 Jan 2024 05:40:07 -0800 (PST) Received: from LOCLAP699.rst-01.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id ly4-20020a0562145c0400b0068688a2964asm3470456qvb.113.2024.01.24.05.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 05:40:06 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 1/4] knownnetworks: pass scan_bss to known_network_add_frequency Date: Wed, 24 Jan 2024 05:39:58 -0800 Message-Id: <20240124134001.20453-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 This prepares to store known frequencies sorted by BSS rank. --- src/knownnetworks.c | 6 +++--- src/knownnetworks.h | 3 ++- src/network.c | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index 04ce74ec..f6284fdc 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -566,7 +566,7 @@ static bool known_frequency_match(const void *a, const void *b) * Adds a frequency to the 'known' set of frequencies that this network * operates on. The list is sorted according to most-recently seen */ -int known_network_add_frequency(struct network_info *info, uint32_t frequency) +int known_network_add_frequency(struct network_info *info, struct scan_bss *bss) { struct known_frequency *known_freq; @@ -574,10 +574,10 @@ int known_network_add_frequency(struct network_info *info, uint32_t frequency) info->known_frequencies = l_queue_new(); known_freq = l_queue_remove_if(info->known_frequencies, - known_frequency_match, &frequency); + known_frequency_match, &bss->frequency); if (!known_freq) { known_freq = l_new(struct known_frequency, 1); - known_freq->frequency = frequency; + known_freq->frequency = bss->frequency; } l_queue_push_head(info->known_frequencies, known_freq); diff --git a/src/knownnetworks.h b/src/knownnetworks.h index e8ffac0b..9f81e308 100644 --- a/src/knownnetworks.h +++ b/src/knownnetworks.h @@ -114,7 +114,8 @@ struct network_info *known_networks_find(const char *ssid, struct scan_freq_set *known_networks_get_recent_frequencies( uint8_t num_networks_tosearch); -int known_network_add_frequency(struct network_info *info, uint32_t frequency); +int known_network_add_frequency(struct network_info *info, + struct scan_bss *bss); void known_network_frequency_sync(struct network_info *info); uint32_t known_networks_watch_add(known_networks_watch_func_t func, diff --git a/src/network.c b/src/network.c index 4723334e..81315746 100644 --- a/src/network.c +++ b/src/network.c @@ -807,7 +807,7 @@ static void add_known_frequency(void *data, void *user_data) struct scan_bss *bss = data; struct network_info *info = user_data; - known_network_add_frequency(info, bss->frequency); + known_network_add_frequency(info, bss); } void network_set_info(struct network *network, struct network_info *info) @@ -1094,7 +1094,7 @@ bool network_bss_add(struct network *network, struct scan_bss *bss) return false; if (network->info) - known_network_add_frequency(network->info, bss->frequency); + known_network_add_frequency(network->info, bss); /* Done if BSS is not HS20 or we already have network_info set */ if (!bss->hs20_capable) @@ -1131,7 +1131,7 @@ bool network_bss_update(struct network *network, struct scan_bss *bss) /* Sync frequency for already known networks */ if (network->info) { - known_network_add_frequency(network->info, bss->frequency); + known_network_add_frequency(network->info, bss); known_network_frequency_sync(network->info); } From patchwork Wed Jan 24 13:39:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13529251 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 5282177F14 for ; Wed, 24 Jan 2024 13:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103615; cv=none; b=puORob+/vXwGtaj026l75QlfDBGEKxOdDkuxeZfnh0sfQ6sBvoQKRAJE4cDC0/yfkCdbnZAoANZB5guoNtrER3iwUCM08+zY78F6ZeUUrBW1/GGgTvXj/Gh8IkSk7GkTLlacYNvwi1YNjR4mIDTMtbXdWdRbti8/No2YwdJzdo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103615; c=relaxed/simple; bh=IOpScdZjK56QxyeEq6eoyt2MdkTVz7Uyww9zTxu21fY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cc+Wg+8XZ8M+q1nSal0fSwhb/cbfMoGDtPExyDaMLKRcgwFvSajGxaMfqBTDCS2z78kIBoiuxw/lx4zxBBiH+WyjM4/vddqrQwzCE7lMBs2XZ6a3tMxpUgmjqGk2D9q8dqxOl2wm1+89TDmpuWGj35anuqYe6K4wmqlURWfJyjM= 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=L9Ex0mOZ; arc=none smtp.client-ip=209.85.219.180 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="L9Ex0mOZ" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-db3a09e96daso4694467276.3 for ; Wed, 24 Jan 2024 05:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706103613; x=1706708413; 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=mICSpAbWMPURceODAsw5vEUXmuHptWdKhLHvVRLjtlE=; b=L9Ex0mOZCaS4cmeyebfIRA1rshYvI00/jROVYqgLduGyIHKIOGSTvyU9yAp5c8oYou sjBgfY0+nhAEGD5fdSAW+LRyuhEVR4RpKiRvqVOdx+H/kt2VDDJrLz1tbJ3pFyBbE+Su 6WlbFGtY2lMCOshf9Akn3lKKYxPrmD8wBdRL4lhCaGh+ftSSK30rr7t+xckUyprERPLX IG7UW8pPMvKE9s+xKr7RBvr+/nMA6eQtkolo+3bhJJalRkhYYCFyuI707gqLQebk0ACr CmZ9iZ3mOtl8e/kPQnV8JpuKFSoCCbP3KlWCGUZ3ICn+re0967BF5rD896agC9LemEfc hCLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706103613; x=1706708413; 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=mICSpAbWMPURceODAsw5vEUXmuHptWdKhLHvVRLjtlE=; b=nNgpHSFFhoco4KqB+y9VgK29qNsxh58ttTbUCH5LSLltaI+KSDUorviGwvij64nizm I9U1Hg+5sBvFYf4pl0foScVLOT+3a12wJPgmjVVuwZDYUvbm2VmvOMOc2TECjKZIjJTC FgE4urHPYd0iQsjtFFieMV1fHKZCZ0pqROW8pY9D9ODyNdk0meiUhj71whYAHbToc9Rz F2vyjin1W/WxZYo9dbEA2g27ziX6cn9W7mNtCxwL1FShXgJBt/v5lGmA3Aso78/tHA4j OVp5jc5y3cDwWdxIIitZ/4KR54l3Qlwkb0XQbm6TSAcYTql/bbCpfltKdCU4crX5+XY0 0Krw== X-Gm-Message-State: AOJu0Yw6+I0UUagFQ0aiEBQfyCQExKEoB5LfA+v8w5sGLzqZbBMFana/ gPKaibZLAc5BMGX7PitENgaQd+zJp3xznV6gZ0GVRYuhFuaSksokQEkIdZjfssQ= X-Google-Smtp-Source: AGHT+IGxytBYUThZWmZYeJXSoSBlFmBCjyDzki+XWCXT2zs2Am0xUGJ07ftzWKfQ6R8RrzHHToUgCQ== X-Received: by 2002:a25:448a:0:b0:dc3:5468:b385 with SMTP id r132-20020a25448a000000b00dc35468b385mr488573yba.95.1706103608262; Wed, 24 Jan 2024 05:40:08 -0800 (PST) Received: from LOCLAP699.rst-01.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id ly4-20020a0562145c0400b0068688a2964asm3470456qvb.113.2024.01.24.05.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 05:40:07 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 2/4] knownnetworks: sort known frequencies by BSS rank Date: Wed, 24 Jan 2024 05:39:59 -0800 Message-Id: <20240124134001.20453-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240124134001.20453-1-prestwoj@gmail.com> References: <20240124134001.20453-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently a quick scan uses the entire known frequency list so ordering really doesn't matter but improvements will be made here to make quick scans "quicker" for large network deployments (with many known frequencies). To prepare for this the known frequency list has been changed to be sorted by BSS rank rather than most recently seen. This makes a lot more sense because IWD should prefer to scan frequencies that had higher ranked BSS's, not just frequencies that were scanned last on the most recent scan. As far as the disk sync goes the ranking is not included, but ordering is. This really isn't a limitation because when IWD starts up there isn't any guarantee its in the same physical location so old scan ranks are likely not valid anymore. The first set of scans will begin replacing the frequencies loaded from disk. --- src/knownnetworks.c | 16 ++++++++++++++-- src/knownnetworks.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index f6284fdc..6e549e02 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -562,9 +562,19 @@ static bool known_frequency_match(const void *a, const void *b) return known_freq->frequency == *frequency; } +static int known_frequency_compare(const void *a, const void *b, + void *user_data) +{ + const struct known_frequency *kf_a = a; + const struct known_frequency *kf_b = b; + + return (kf_b->rank > kf_a->rank) ? 1 : -1; +} + /* * Adds a frequency to the 'known' set of frequencies that this network - * operates on. The list is sorted according to most-recently seen + * operates on. The list is sorted according to the rank of the BSS on that + * frequency. */ int known_network_add_frequency(struct network_info *info, struct scan_bss *bss) { @@ -578,9 +588,11 @@ int known_network_add_frequency(struct network_info *info, struct scan_bss *bss) if (!known_freq) { known_freq = l_new(struct known_frequency, 1); known_freq->frequency = bss->frequency; + known_freq->rank = bss->rank; } - l_queue_push_head(info->known_frequencies, known_freq); + l_queue_insert(info->known_frequencies, known_freq, + known_frequency_compare, NULL); return 0; } diff --git a/src/knownnetworks.h b/src/knownnetworks.h index 9f81e308..36106501 100644 --- a/src/knownnetworks.h +++ b/src/knownnetworks.h @@ -96,6 +96,7 @@ typedef void (*known_networks_destroy_func_t)(void *user_data); struct known_frequency { uint32_t frequency; + uint16_t rank; }; void __network_config_parse(const struct l_settings *settings, From patchwork Wed Jan 24 13:40:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13529249 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (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 D459E199BA for ; Wed, 24 Jan 2024 13:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103612; cv=none; b=VLsLeQrWuyB9mRU5IBEoLb71oaibD7s4IiKml52FHmEhDJcvxkRXKzXVJxMhzNa/06FSDju1XpkUKRSzvAQHve5sUlfXkzIK/wojdrjjbEpA2f6ue+lPmPafjuTCYfOAeh5rrgfrYwmBN7wPmFhHOck3iRdB/La3R9pU6CjrQJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103612; c=relaxed/simple; bh=b2hyvLV4lCyvBDqXs8ONm+gukrkbS04d+igpwc055/U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JFoRwnSu+ZGzUJt8w1cQalEBCo0pbOOTJcKl+wQe9XgwHit4wOijBtoWDn8ArGs7TjSsHiil3gbauxgezxAdZIdpYJIabsf9CqPl2fCxia8/1f8tYdn0zF8e91cySeKlbMroN7Nem0i9vO9vEG9Y6x9muPixUIQhAdDznn8X850= 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=VEYHpccO; arc=none smtp.client-ip=209.85.219.48 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="VEYHpccO" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6853f6ff6e1so27587566d6.2 for ; Wed, 24 Jan 2024 05:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706103609; x=1706708409; 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=lepWR7JYPDHeydw5l0Odqk7+dLy/r9WpLDTU/O1ZBcU=; b=VEYHpccOmrvdDDw5eohMcCl5UUS7vzcalq3/aCJU8D/fU0FA6dL1yUxq19PwclEwCR DJ48rG6mtrDbEuD5qA3krtKrEFw4aCMHIF0jrbD0FL+Y8S0/8LQcInn3isCa2W1Qsz2V l6DzPZO0ModNNyFsPtP9/GbW8PMSM1bAjV7gx6qCAMRNz/owQtzUiJZAAOdLr+U2v8fh 3QsNXpJYwZEjboh7NWQm3Q4SZnudEmY+cm0gaQF4KdPfm754mIrpfLyzqiO8xwYPMI0x bx7avlmWrq4iHF47aSyGBvBOarzHhAP0X2kAk3v2RsP6zaCXj/JZyE+rKhnTnAy6KklK +Q1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706103609; x=1706708409; 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=lepWR7JYPDHeydw5l0Odqk7+dLy/r9WpLDTU/O1ZBcU=; b=c9HeyBlQZjaHQF108cSCvszytsRlM97y/qEBzaZSr7DfKNvT9Fr1d14FkLIzl/yjPv OW3dxhYcA/KlcNcfgonuxXyTe0634zd6zkRd4LuYdYQdfxdsu+BJnxMYoATZgAbq2UwV y0CwDidvC11jeORLpHEGCF3xlQ15he9XLWvM3nIuwDsyPkq93zsNA8aTuh3lh2+g6bsJ MpnubxHN/rK8XaESC8gB679qhpj+S8Y9Bk6BxJbGaqtiPIqCCaeCqJHeLZ20aFhcbNp/ y3cNxoDBo9A7hxWD9lbNVOb9RV9L+QE5T6tZ29xTWZ619EMhkdRci4UYULt+4qTCx0ay u7Rw== X-Gm-Message-State: AOJu0YxwpuoyCqw4KiHBPbGX9nr7NuQL9diJZk7iiCfm/9jGgaZqVift RI78bSoN53kdn7O9S5K7NYIP007QgvGA50Hv5du4kF59efIUVjV4KItNPuHcj2E= X-Google-Smtp-Source: AGHT+IEFld+sAzpu+5Qxle5lq2+D/AzjToek6V3w2nLHhlYjlg7FNFnlcKUhyq4a5xDCWIwjr+GFlw== X-Received: by 2002:ad4:5b85:0:b0:686:abae:eb69 with SMTP id 5-20020ad45b85000000b00686abaeeb69mr1736924qvp.130.1706103609269; Wed, 24 Jan 2024 05:40:09 -0800 (PST) Received: from LOCLAP699.rst-01.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id ly4-20020a0562145c0400b0068688a2964asm3470456qvb.113.2024.01.24.05.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 05:40:08 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 3/4] station: knownnetworks: limit quick scans to 5 freqs per network Date: Wed, 24 Jan 2024 05:40:00 -0800 Message-Id: <20240124134001.20453-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240124134001.20453-1-prestwoj@gmail.com> References: <20240124134001.20453-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In very large network deployments there could be a vast amount of APs which could create a large known frequency list after some time once all the APs are seen in scan results. This then increases the quick scan time significantly, in the very worst case (but unlikely) just as long as a full scan. To help with this support in knownnetworks was added to limit the number of frequencies per network. Station will now only get 5 recent frequencies per network making the maximum frequencies 25 in the worst case (~2.5s scan). The magic values are now defines, and the recent roam frequencies was also changed to use this define as well. --- src/knownnetworks.c | 9 ++++++--- src/knownnetworks.h | 3 ++- src/station.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index 6e549e02..fe0fce09 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -518,7 +518,8 @@ struct network_info *known_networks_find(const char *ssid, } struct scan_freq_set *known_networks_get_recent_frequencies( - uint8_t num_networks_tosearch) + uint8_t num_networks_tosearch, + uint8_t freqs_per_network) { /* * This search function assumes that the known networks are always @@ -530,7 +531,7 @@ struct scan_freq_set *known_networks_get_recent_frequencies( const struct l_queue_entry *freq_entry; struct scan_freq_set *set; - if (!num_networks_tosearch) + if (!num_networks_tosearch || !freqs_per_network) return NULL; set = scan_freq_set_new(); @@ -540,10 +541,12 @@ struct scan_freq_set *known_networks_get_recent_frequencies( network_entry = network_entry->next, num_networks_tosearch--) { const struct network_info *network = network_entry->data; + uint8_t freqs_found = 0; for (freq_entry = l_queue_get_entries( network->known_frequencies); - freq_entry; freq_entry = freq_entry->next) { + freq_entry && freqs_found < freqs_per_network; + freq_entry = freq_entry->next, freqs_found++) { const struct known_frequency *known_freq = freq_entry->data; diff --git a/src/knownnetworks.h b/src/knownnetworks.h index 36106501..108f334e 100644 --- a/src/knownnetworks.h +++ b/src/knownnetworks.h @@ -114,7 +114,8 @@ struct network_info *known_networks_find(const char *ssid, enum security security); struct scan_freq_set *known_networks_get_recent_frequencies( - uint8_t num_networks_tosearch); + uint8_t num_networks_tosearch, + uint8_t freqs_per_network); int known_network_add_frequency(struct network_info *info, struct scan_bss *bss); void known_network_frequency_sync(struct network_info *info); diff --git a/src/station.c b/src/station.c index a6442d3e..1b34b956 100644 --- a/src/station.c +++ b/src/station.c @@ -64,6 +64,9 @@ #include "src/eap-tls-common.h" #include "src/storage.h" +#define STATION_RECENT_NETWORK_LIMIT 5 +#define STATION_RECENT_FREQS_LIMIT 5 + static struct l_queue *station_list; static uint32_t netdev_watch; static uint32_t mfp_setting; @@ -1434,7 +1437,9 @@ static int station_quick_scan_trigger(struct station *station) return -EAGAIN; } - known_freq_set = known_networks_get_recent_frequencies(5); + known_freq_set = known_networks_get_recent_frequencies( + STATION_RECENT_NETWORK_LIMIT, + STATION_RECENT_FREQS_LIMIT); if (!known_freq_set) return -ENODATA; @@ -2757,7 +2762,8 @@ static int station_roam_scan_known_freqs(struct station *station) const struct network_info *info = network_get_info( station->connected_network); struct scan_freq_set *freqs = network_info_get_roam_frequencies(info, - station->connected_bss->frequency, 5); + station->connected_bss->frequency, + STATION_RECENT_FREQS_LIMIT); int r = -ENODATA; if (!freqs) From patchwork Wed Jan 24 13:40:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13529250 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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 B026660BB3 for ; Wed, 24 Jan 2024 13:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103613; cv=none; b=MBdj003rRbgZBKAVHUZvg2AelZ5+/sb1SmdLnyNfY+y88mcromkCYJvUitejzO+/3FwL7HkmlVVda5ms9aoRzQzuGJfND3/xlirGIuk7zX/wWkTACzoKEFY3JKZHI4AuOMBy7MWgZwE0LH8z7FCFtoaK9VUyMHMMS2WMEwtgLxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706103613; c=relaxed/simple; bh=qVUe8BPZnq+dT6elRok0k5v/vnyX0lzsZGhFvdSGGcA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kLQx+QU2SET+t4yMKAZoSloPYd55ixpDO04A3pOyPRXJ7c1J92L8yukY0Vyi+M/lQvjGSLiz1cHOa0BrweHW+71BKz6dh77txybWbjnd2aaWPcguhtuDzzdXJWMVIEYEw90C+SenR6Mm7CnwPXHaAy2xojxVp46V8KU447XAGyE= 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=Rq4Cmk1Q; arc=none smtp.client-ip=209.85.128.180 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="Rq4Cmk1Q" Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-5ffd5620247so36703397b3.0 for ; Wed, 24 Jan 2024 05:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706103610; x=1706708410; 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=yjhxB13PubYFTi/ivDF1ihuXnkM9cVlu0OUeGQW96W8=; b=Rq4Cmk1Q09cNSxy3NOVs/WJlW7ppoPX3yz/1jZkSKzSKjvC15ob5+UQU0sHR79UP6P cAm8NVOZ+QP92i1q18amhrXgJtvIHTXQ/Nx6jEwagJUJf2OaCj064nZYuotp/WzhNaMy KOYfXyDXbVZ56/AtZ+MFPio3fSnllziIyUawDg0f5Ce+hzBpN2zHsPlaVWxOySZCllI6 NWsXTeSVRe6DgkeFhLaf4MMT+JSXmRB+LzrkgoKJnoglv5IGZCoU4RNLgUFWCVvCpg4N NLxp4IoipRlB6veQzsGUlpFegpND2KKIdq6VIoaPypOwBlw5pQyZqBNTAeacW9VAo1/b CVHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706103610; x=1706708410; 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=yjhxB13PubYFTi/ivDF1ihuXnkM9cVlu0OUeGQW96W8=; b=lz7oeQgEXabihnHjw7PuVmrtyu69HTdZ92+veIJ+QRWe690hK5/qRxGyC9RqbGsPfK WqJqXluiIcTmEn1gcXCTyfDko4SyFikNlRaPeALAnNL/wYIF/yBpvCgvII0507Dt1fa7 2AcclkKHk9YCtE2YRaa4c0olnEJqapNejuweaLFLplV03bc+swDMMwXgpCgyC5ZbqfnG i20ngQbw/fS63jH1/LCGbJ0g6JI0G2u6S8W/RoFEVsH7KWDESup2vDRe21F1zrAVOCmc fwWSElhXYpYxERYzvz8XStpQ4F0dIxklgxET63hKgmVZEoZsb373m4mCw0OS7tY7EKv0 y52Q== X-Gm-Message-State: AOJu0YwsmSNIE3uktx83Y0NAXDv34ntNwZ9585wChfLJ6pZ4VXsU3eaL DrImkIMBEfKNZyPGAbsTBM86ZxGNHJfT4rBnhkTb5Eb+zmsUtWxzM+dJCrFJpBo= X-Google-Smtp-Source: AGHT+IGzDLf+908YuqDm4eBohrNfZwgYBQUCTBQZgiHJU0HO8y8cHuXDCCqo+fx7IMBZf+lm+segww== X-Received: by 2002:a25:84c4:0:b0:dbd:bf0d:d97f with SMTP id x4-20020a2584c4000000b00dbdbf0dd97fmr653063ybm.126.1706103610297; Wed, 24 Jan 2024 05:40:10 -0800 (PST) Received: from LOCLAP699.rst-01.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id ly4-20020a0562145c0400b0068688a2964asm3470456qvb.113.2024.01.24.05.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 05:40:10 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 4/4] auto-t: add test for known frequency sorting/maximum Date: Wed, 24 Jan 2024 05:40:01 -0800 Message-Id: <20240124134001.20453-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240124134001.20453-1-prestwoj@gmail.com> References: <20240124134001.20453-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Modify the existing frequency test to check that the ordering lines up with the ranking of the BSS. Add a test to check that quick scans limit the number of known frequencies. --- autotests/testKnownNetworks/frequency_test.py | 110 ++++++++++++++++-- autotests/testKnownNetworks/hw.conf | 1 + 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/autotests/testKnownNetworks/frequency_test.py b/autotests/testKnownNetworks/frequency_test.py index 83e51c06..c2fd1290 100644 --- a/autotests/testKnownNetworks/frequency_test.py +++ b/autotests/testKnownNetworks/frequency_test.py @@ -4,17 +4,15 @@ import unittest import sys sys.path.append('../util') -import iwd from iwd import IWD from iwd import PSKAgent -from iwd import NetworkType -import testutil +from hwsim import Hwsim import os from configparser import ConfigParser class Test(unittest.TestCase): def connect_network(self, wd, device, network): - ordered_network = device.get_ordered_network(network) + ordered_network = device.get_ordered_network(network, full_scan=True) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) @@ -30,7 +28,7 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(ordered_network.network_object, condition) def test_connection_success(self): - wd = IWD(True, '/tmp') + wd = self.wd psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) @@ -38,6 +36,11 @@ class Test(unittest.TestCase): devices = wd.list_devices(1) device = devices[0] + + # Set the signals so that the 2.4GHz ranking will be higher + self.ssidccmp_2g_rule.signal = -2000 + self.ssidccmp_5g_rule.signal = -8000 + # # Connect to the PSK network, then Hotspot so IWD creates 2 entries in # the known frequency file. @@ -75,8 +78,10 @@ class Test(unittest.TestCase): # self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_uuid) - self.assertIn('5180', psk_freqs) - self.assertIn('2412', psk_freqs) + + # The 2.4GHz frequency should come first, as it was ranked higher + self.assertEqual('2412', psk_freqs[0]) + self.assertEqual('5180', psk_freqs[1]) self.assertIsNotNone(hs20_freqs) self.assertIsNotNone(hs20_uuid) @@ -92,6 +97,10 @@ class Test(unittest.TestCase): psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) + # Now set the signals so that the 5GHz ranking will be higher + self.ssidccmp_2g_rule.signal = -8000 + self.ssidccmp_5g_rule.signal = -2000 + # # Reconnect, this should generate a completely new UUID since we # previously forgot the network. @@ -120,8 +129,78 @@ class Test(unittest.TestCase): self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_uuid2) self.assertNotEqual(psk_uuid, psk_uuid2) - self.assertIn('5180', psk_freqs) - self.assertIn('2412', psk_freqs) + # Now the 5GHz frequency should be first + self.assertEqual('5180', psk_freqs[0]) + self.assertEqual('2412', psk_freqs[1]) + + def test_maximum_frequencies(self): + psk_agent = PSKAgent("secret123") + self.wd.register_psk_agent(psk_agent) + + devices = self.wd.list_devices(1) + device = devices[0] + + # Connect and generate a known frequencies file + self.connect_network(self.wd, device, 'ssidCCMP') + + self.wd.unregister_psk_agent(psk_agent) + + # + # Rewrite the known frequencies file to move the valid network + # frequencies to the end, past the maximum for a quick scan + # + config = ConfigParser() + config.read('/tmp/iwd/.known_network.freq') + for s in config.sections(): + if os.path.basename(config[s]['name']) == 'ssidCCMP.psk': + config.set(s, 'list', "2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484 2412 5180") + break + + self.wd.stop() + + with open('/tmp/iwd/.known_network.freq', 'w') as f: + config.write(f) + + self.wd = IWD(True) + + devices = self.wd.list_devices(1) + device = devices[0] + + device.autoconnect = True + + device.wait_for_event("autoconnect_quick") + + condition = "obj.scanning == True" + self.wd.wait_for_object_condition(device, condition) + + condition = "obj.scanning == False" + self.wd.wait_for_object_condition(device, condition) + + # + # Check that the quick scan didn't return any results + # + with self.assertRaises(Exception): + device.get_ordered_network("ssidCCMP", scan_if_needed=False) + + device.wait_for_event("autoconnect_full") + + condition = "obj.scanning == True" + self.wd.wait_for_object_condition(device, condition) + + condition = "obj.scanning == False" + self.wd.wait_for_object_condition(device, condition) + + # + # The full scan should now see the network + # + device.get_ordered_network("ssidCCMP", scan_if_needed=False) + + def setUp(self): + self.wd = IWD(True) + + def tearDown(self): + self.wd.stop() + self.wd = None @classmethod def setUpClass(cls): @@ -129,10 +208,23 @@ class Test(unittest.TestCase): conf = '[General]\nDisableANQP=0\n' os.system('echo "%s" > /tmp/main.conf' % conf) + hwsim = Hwsim() + + cls.ssidccmp_2g_rule = hwsim.rules.create() + cls.ssidccmp_2g_rule.source = hwsim.get_radio('rad1').addresses[0] + cls.ssidccmp_2g_rule.enabled = True + + cls.ssidccmp_5g_rule = hwsim.rules.create() + cls.ssidccmp_5g_rule.source = hwsim.get_radio('rad2').addresses[0] + cls.ssidccmp_5g_rule.enabled = True + @classmethod def tearDownClass(cls): IWD.clear_storage() os.remove('/tmp/main.conf') + cls.ssidccmp_2g_rule.remove() + cls.ssidccmp_5g_rule.remove() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testKnownNetworks/hw.conf b/autotests/testKnownNetworks/hw.conf index 8a7ef73a..f68b63a5 100644 --- a/autotests/testKnownNetworks/hw.conf +++ b/autotests/testKnownNetworks/hw.conf @@ -2,6 +2,7 @@ num_radios=5 start_iwd=0 reg_domain=US +hwsim_medium=yes [HOSTAPD] rad0=ssidNew.conf