From patchwork Tue Jun 18 16:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702761 Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) (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 AB58613C697 for ; Tue, 18 Jun 2024 16:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729942; cv=none; b=aj07x5iCYEphTO/mfhV5SBuwsrCVopNUysOmTvvaUuRfDO6epRMDf87gEb18cxQL9nJtOtsebDBxdkCUpfDkaCWkrG6hWVGVxMOdj1pdJGO6PmB2PY0YtTfdJTN8+n5E0APZzVuvzBeysUdkZ4opDy9s0W8lfC7pLsNaJyIdPuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729942; c=relaxed/simple; bh=FY6UPEShqvDyoyXcx0u682D4qTTz5UU+Z9Tx9PfyozA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=I5sQIZXxwtYkd6F8hAM1oOlx5jptW4+NDRTbDWiqGzQk6+j0C7hVw0T05IYJcxAZwDkv8/NyZufGun9BMywhlbuB+h5r7hu8pD72ikQyucKHxxK8VUvZCmV1tffBCqVK2x4WJGdtcNx0ZTloVWqKAlVVdjf9Agtpmpkw3VcMP2o= 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=PDe3VpSD; arc=none smtp.client-ip=209.85.222.45 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="PDe3VpSD" Received: by mail-ua1-f45.google.com with SMTP id a1e0cc1a2514c-80b7699abcaso1574725241.3 for ; Tue, 18 Jun 2024 09:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729939; x=1719334739; 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=abMytJVtQ4ZdUltEYUT+QWW86G/3e5WAqgPv7RO4xPQ=; b=PDe3VpSD0JZGB+bGuOR7F8HxbOQWBIMUOFHW7IguqGYd7hzFXzsoFLSh3YT0xp9TJs GMZzkatU0Gygw6i1j9KIVcM4rmMb19zP0dKT1xzA53PFpbKAJS3icknwVWIyn5BDCqWE clzf9vsmZmlIlyTZmKtKQ9Z2NmGSur6/JDrTFzXYHsjbvp/xE9yxY0kfj3JMGIw1+okA zTEsJ/sTI97K8wNXqc+L0eXv8TbmKqTXM3hAlXWOXzHMGHvcxEdN5OPhYaH2Gf9j+c0O T15AfFnLBI+Bf+huUMEipvXNVd4KLhirPheQSwMh/nC9EEYBFyHCxqitGcZ5ZR7tsoEp jkJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729939; x=1719334739; 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=abMytJVtQ4ZdUltEYUT+QWW86G/3e5WAqgPv7RO4xPQ=; b=vKLA2iatNn0eXsnXsOZLarkCtLbsGcRhJvoIeYALneHsfqWbGZl9UBnzcnT5TW0994 XRrjbOs77RBt+/Qp1ZFUJ8hedS0Epza9ekknTkttjH+J1DZgqGM6VWni5+0l0mGVDLhW 5r1IxEB6qfLoQBHCay7Nlm2/6UN7cK6zBD56SZuw2qA0GBlF68BoLIJwK59vnrw/tXmy BkqQOv4lLMEw/pcFmfCByGhH4cRcdokpc4os4uMwEMAFH9Tg4dN9hof/T4yt0dc+CbBC luvjeeYsg4VIztD5KWmHFdJnq3UGVMHV0IP4eEssBHWxnE3rAaoVyBTdpyrYXliXwKHp 6LnQ== X-Gm-Message-State: AOJu0Yzc2RQdt4z7HLfAk8rla4qdQj5ysPut8fGZxr5f+oFgnYmag71n +6by/qL2GVL1oGbsHxkcQN5JAc1f+CcJbD9Su6l7IjPb+TpKQqmfKBeohg== X-Google-Smtp-Source: AGHT+IGRX5qJuMHkeGxIBIqqAHTmtQQRR2SY6GT1ilz4O8aT/cEicw2JbvFiOy42280wUh9F8ZuAMA== X-Received: by 2002:a05:6122:1799:b0:4ec:fe80:ca3f with SMTP id 71dfb90a1353d-4ef277c5fa5mr578426e0c.13.1718729939181; Tue, 18 Jun 2024 09:58:59 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:58:58 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 01/10] netdev: downgrade L_WARN_ON for ensure_eapol_registered Date: Tue, 18 Jun 2024 09:58:45 -0700 Message-Id: <20240618165854.113598-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 warning is guaranteed to happen for SAE networks where there are multiple netdev_authenticate_events. This should just be a check so we don't register eapol twice, not a warning. --- src/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netdev.c b/src/netdev.c index af069724..5b79d267 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -2898,7 +2898,7 @@ static bool kernel_will_retry_auth(uint16_t status_code, static void netdev_ensure_eapol_registered(struct netdev *netdev) { - if (L_WARN_ON(netdev->sm)) + if (netdev->sm) return; netdev->sm = eapol_sm_new(netdev->handshake); From patchwork Tue Jun 18 16:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702762 Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.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 B4867132492 for ; Tue, 18 Jun 2024 16:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729943; cv=none; b=jxpjx52DrO7S/YypE2O/6oGeDbhYW1a+zG5DcKcpSM66F4FNFco8432aNH9MCOfseB6+fK4TEGBeAejnXPiQIaQgVOEaHRxpFxc2eRowQxIu4/6UiHllPSqil0wL6CmaUg5bIHTiF37x+V9JaboFg8epnC1wMF2FX1hRarVp6Bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729943; c=relaxed/simple; bh=pgbCuaJSS9JWFrQpAd/Ot034FCwNFC+fNRkYN6kwFPg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LBThrI/IniWBZFmaSBSMg1pcUixTcws6t5jBUTCkMs4YcZ4nWa22lfinwIgVIpoDtS2E686Fasievc0hCrnhI48dSJdvnhu6EidMcUIml1YbYqreCj3u7eCUwfdgyLnDMHj6Ct4xGk/IKdqvpLJ0+QBbQWGHab1MsgExLi8DxE0= 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=a/61B+2F; arc=none smtp.client-ip=209.85.221.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="a/61B+2F" Received: by mail-vk1-f176.google.com with SMTP id 71dfb90a1353d-4ed083c2874so1270849e0c.2 for ; Tue, 18 Jun 2024 09:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729940; x=1719334740; 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=CQCG5OoDiAsKEOEh7vmRafPWObVvz/Xdd+/fPbFqSVc=; b=a/61B+2FRsJVy07LTBjpaugxi7lEWY/5hvchmmn/qlP/6Xj51EgqxIbu+i73dRjpXk kaLci5aRyL0WRFSwT0k0lPehmeteWjSsshkIosPuJfgbu5hAE5/MbMtJ/a4RXddTVR7h VVqFfPN/olCUCtTOzGpNZhhDHk3fw9nKnbQZLDLYLtU4mbI5emt7Hxnt9sTTzE8mgDKL QVOvpFj3bwCDISwazfl+VV1E9lkERMFH7ik2ZLMP1EFeU52toZWEjgd8AMX+HFtVFnGy BiMZpsKJ+jgTHEAzBK4jw7i1i0nohmijsiO3rw5z8LHaQu2sqqWe5glkKrijCbXOZjto ojAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729940; x=1719334740; 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=CQCG5OoDiAsKEOEh7vmRafPWObVvz/Xdd+/fPbFqSVc=; b=R2EgC5nX6uOVUN9Fvn3VLkeB0HDp14IbRE/LhpDD6locu8Btcqo8yAaeyY0HBspCN/ ENvefRdT7m/IpJcuAniMYr/rGodTD0sfTvu4ynotCUXFVJk7VuCGPIbhIMrlf4Kxsugv I7dIRJx7Ecxr2UFg0tpgmLz5VgyyYP6XuR1HfocZ/73gA9Lh9yPwV0CtFaRKRX6EYxNW 2HFO7mVHbdNmfjj4YWAKuRsCg5F1JixvAGMj9cZjelg7kZwyoKx5YhxRSrliymS+gyfJ jiqe5eC8i1v+Vr0xReuAXAh/HLKXL86DYNeiGSX6/hOHYHVaDZk4xOi0NX6lpZeYzQkf C6dQ== X-Gm-Message-State: AOJu0YwYRNle0zPfFxyCCvWn6msZ7fG7pHrYVqLB+CVyUtOfvXVZMhvF 2XGPTSj1wvEo95mXWzZCVuKn+9zefuadXoT+nG9/bcAng7zZIvhMfnh70Q== X-Google-Smtp-Source: AGHT+IH2erd/v5EHOClMZ4a4waSbQPBYygcBx6AqevSd/WJ/JFReOY2BABy9zVTdzsmYl/OVXu6zWA== X-Received: by 2002:a05:6122:2008:b0:4ec:f43a:ab8f with SMTP id 71dfb90a1353d-4ef2770b526mr515320e0c.7.1718729940398; Tue, 18 Jun 2024 09:59:00 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:00 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 02/10] nl80211util: add ATTR_SURVEY_INFO to parse_attrs Date: Tue, 18 Jun 2024 09:58:46 -0700 Message-Id: <20240618165854.113598-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-1-prestwoj@gmail.com> 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 Tue Jun 18 16:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702763 Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.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 CE74B13790B for ; Tue, 18 Jun 2024 16:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729944; cv=none; b=XlFDwz0WjQUR4DrDFzj22c1RAknSOB+T0qsMgcnS12F6ZmyvXBQ4idSWoIHCF9f4H5Fe38PzonMOKGOb37Idhuf4yM4pzv0w+npyZW7N7iZLkdkhlbgMN1eBv2Rcvpqkc4vajFJoiiDKTInqTOWeFGubRZoaWyfdYHTdrW780ZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729944; c=relaxed/simple; bh=kUlFaFk8bdOrk2QQqJZbMa7YJh6YVIpJQGjAcx++SnA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DT/NsnfT5SdMtv6yj2V/AzRSB2088hSEROL0RHDq3HpiU3P6Ubxi1+EcC3I1h9D5p5b4EvKYEqxxIx1B9B6XV3p30aTQ6J76Zto+Sv4WHutW4dXxavIezgeX86oEMsHSqyKLGAe21l8zDtxGCcBnMtXwl5ob4pRfCe382T1S3Jo= 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=fjjleSJk; arc=none smtp.client-ip=209.85.221.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="fjjleSJk" Received: by mail-vk1-f173.google.com with SMTP id 71dfb90a1353d-4ecfbf16c77so1637493e0c.3 for ; Tue, 18 Jun 2024 09:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729941; x=1719334741; 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=o80ybhoymnMckPDGCG9HVqYQVnI6ilk8pqgTtBYW3ZU=; b=fjjleSJkOUo67P82fHLY0GoJfAijKs78ZfF7RPsvN6cpxd8aAbjwqXrH8h0VgnTQQF 7g3spKRlrmqhxfjhzV5YaGxQS4fU3m2YsL+v8L4ZDr44yS0ZpK/8cUO55SSvhLJevuNO +w2SYwS6/LZV17gXwP1gSmgfDIJ96TQi+Mix9N3sIipHByhe82h7XBqG5Ohlt5aHAUO9 cUjWppojmkL08VLJqMMppH4hpb9OkfM2HQ4/nxXDWQqFCrbcJuTtqyy62Sani4ec6Heq HZzrPKiNxmAeA8ekcz3iHvp+1k2DXcrj6NQgc+GRlF9oS0a+ng1OSOwey7+1oDUFMscI Z1+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729941; x=1719334741; 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=o80ybhoymnMckPDGCG9HVqYQVnI6ilk8pqgTtBYW3ZU=; b=a7kE2lfhgohHqs0I9FzCUaXZKjLgQkl5hw4GLbRx7HtZsqffIgBAlcAWljtWTBqeZe TftSCx/Kp7zAlZhz5/xhKTihSHThciJY5wIXvJ6glwyCwlZTefs5lKk3NIAbr6LDSk5f aKpddzQV0dzcQb283XfZ/A4CJsMiix90u/ai/LN64Unb6VeeRjcBy1BgtqbKtEdqrst+ gQFbboNOBzYFv6msFYac52qB1B7zR+N0iGqQlYJu8OWLAnJd+XpIEstJ2+rRWCNHbTkh kD1mPQ9Gvp8VnTPqN00bDK/2liM4DOYg4Px2Adkh3LlNoyASDAakcxzn2+4uWv9H5Zg1 /RWA== X-Gm-Message-State: AOJu0YycZgcThzldiPzdQhmpk6FT8Zi+2jQTBT8BgMU7AK4AO8A7In10 FMAsWgpNiSGQiqZBrZqJTp/O2mTsABHNASnktTDedgkSIFfUhkEmhXPkWw== X-Google-Smtp-Source: AGHT+IHrQwp0J2o6VTcGqXdPbu573eHhzyX12bwPgvPk+1JBA4U+aB07UH+RSZCA2TwdDMqYzr9FrQ== X-Received: by 2002:a05:6122:3c8a:b0:4ec:f4a2:389c with SMTP id 71dfb90a1353d-4ef276f7cc3mr558348e0c.6.1718729941580; Tue, 18 Jun 2024 09:59:01 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:01 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 03/10] nl80211util: refactor nl80211_parse_attrs for nested variant Date: Tue, 18 Jun 2024 09:58:47 -0700 Message-Id: <20240618165854.113598-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To prep for adding a _nested() variant of this function refactor this to act on an l_genl_attr object rather than the message itself. In addition a handler specific to the attribute being parsed is now passed in, with the current "handler_for_type" being renamed to "handler_for_nl80211" that corresponds to root level attributes. --- src/nl80211util.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/nl80211util.c b/src/nl80211util.c index 15968d7d..4a402e2f 100644 --- a/src/nl80211util.c +++ b/src/nl80211util.c @@ -37,6 +37,7 @@ #include "src/util.h" typedef bool (*attr_handler)(const void *data, uint16_t len, void *o); +typedef attr_handler (*handler_for_type)(int type); static bool extract_ifindex(const void *data, uint16_t len, void *o) { @@ -150,7 +151,7 @@ static bool extract_u8(const void *data, uint16_t len, void *o) return true; } -static attr_handler handler_for_type(enum nl80211_attrs type) +static attr_handler handler_for_nl80211(int type) { switch (type) { case NL80211_ATTR_IFINDEX: @@ -199,10 +200,9 @@ struct attr_entry { bool present : 1; }; -int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) +static int parse_attrs(struct l_genl_attr *attr, handler_for_type handler, + int tag, va_list args) { - struct l_genl_attr attr; - va_list args; struct l_queue *entries; const struct l_queue_entry *e; struct attr_entry *entry; @@ -211,10 +211,6 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) const void *data; int ret; - if (!l_genl_attr_init(&attr, msg)) - return -EINVAL; - - va_start(args, tag); entries = l_queue_new(); ret = -ENOSYS; @@ -223,7 +219,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) entry->type = tag; entry->data = va_arg(args, void *); - entry->handler = handler_for_type(tag); + entry->handler = handler(tag); l_queue_push_tail(entries, entry); if (!entry->handler) @@ -232,9 +228,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) tag = va_arg(args, enum nl80211_attrs); } - va_end(args); - - while (l_genl_attr_next(&attr, &type, &len, &data)) { + while (l_genl_attr_next(attr, &type, &len, &data)) { for (e = l_queue_get_entries(entries); e; e = e->next) { entry = e->data; @@ -252,7 +246,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) /* For nested attributes use the outer attribute as data */ if (entry->handler == extract_nested) - data = &attr; + data = attr; if (!entry->handler(data, len, entry->data)) { ret = -EINVAL; @@ -285,6 +279,24 @@ done: return ret; } +int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) +{ + struct l_genl_attr attr; + va_list args; + int ret; + + if (!l_genl_attr_init(&attr, msg)) + return -EINVAL; + + va_start(args, tag); + + ret = parse_attrs(&attr, handler_for_nl80211, tag, args); + + va_end(args); + + return ret; +} + struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex, const uint8_t addr[static 6], uint16_t reason_code) From patchwork Tue Jun 18 16:58:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702764 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 2458713A400 for ; Tue, 18 Jun 2024 16:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729945; cv=none; b=QGnXQFdmMRXGQ9vimTuYQF5eP9Dg1WKhZz7Gxenb05/VmmYQY9yrSipK3H+5mAgpwGpmWghjMoAwNqUMcTRKoHep1WtnaA2PgdmxJtMpgjRb3fm6tv9YfKLAKNX1fD/ftAbCkLNeMUPGqcS7IWy+Pki0nNc3cmI+lFSG98GE6WE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729945; c=relaxed/simple; bh=6s4rvgofKsDSmjnNfuDWJpl4Px6C6YYOBUQeQmTkgkI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mBVvJxuUw6rJkS6WySPQCGqDl2ZO/I+++CslzbCDYeq35Ve157/soxqOlizZ+lAFCz2eYck/P4Xtijdrs1hRarRZzjRnai9lFeOKieFkYfDpc2aSBhlISNvTLbFRzq5QU2J2rDXGmuuRVrD4/gF/r57qQ7DgEPEnzY4VZ8MZY2I= 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=SHbP1v+4; arc=none smtp.client-ip=209.85.222.169 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="SHbP1v+4" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-795a4fde8bfso341079985a.2 for ; Tue, 18 Jun 2024 09:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729943; x=1719334743; 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=z3cOci0lJOT3IlWP5eruS0De6L1xgUbgkNwRvi8idU8=; b=SHbP1v+4ht5d3x79icPAnbPV/kw0MTtvqmaoXo95G7ombjATBwZub35tDP1iympgOW uUHI4w4rzPuWIq+yr0D63hD0Ii/ZEd/zONE7anrc2ZQD67s+g6cONWcvz8VRfhKLlWbK +OgnbD/HjW1eU2ZkGqMt25+MeqdgOBB3p2I5MswoY8AOkiFmwa5hlW/wXcmfrk4JrIXi 7zkqpDNR46zKBUvb8p+todou16Wiq7hLj+Y3LKYFz0cQ45/XtwG6Q3tlx+RzRrNUcDuY 7e337wvLC/O1Foo9ZMnW7BYRaZtP9Ni4vr9Vp/2D6uk2bvs2vlRgU4CZxBMHAXs7ffKT SL+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729943; x=1719334743; 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=z3cOci0lJOT3IlWP5eruS0De6L1xgUbgkNwRvi8idU8=; b=ESaUnyDcrDYB3G5qlVln23miOUBocLydMs7HKHpH+4JFgsg3lBv9npGUSbLwDcQnPP rg377fkPBCBzg/eu6QCL+wW0vKFVRy/N7bqaz8uqBqSrRULe2f9uXsmYk4aHtrY2dee0 mYVZGot8AR6qpbVKxFU0Ccu0qTX5vPuauzsTIxskD1ImoYhl7lXXfRAIaMwB5troraYB votfpV0ZKjhxM7ioehl9PyNTE69lrVui0/3Y4i/SUcCqBhjzYJQopOABX4WKZk/VQ4fk nDyjwn1WdrGTz86fC1fEiGz4XMiftqIFfm4r5pJSX71XpECuEZ219/3w9gDSFk/DEMvk uvsw== X-Gm-Message-State: AOJu0YwJTt1ZqDZcuPfntIRPiSJAsCznN/xZXcZbSBmPCuDXDTFl7BgR 3eU0LdMbeAEs/0yB8w3+r07Bopwye62hgN1aQm+4KP2xud2JR3/WeB4xZQ== X-Google-Smtp-Source: AGHT+IE0bgwZ30QA3zuFO/m86SBhd0EWGo6Ou4iHRmqzSKf6YfuaWP089LPh5h44ATGvSn6B6L7nEw== X-Received: by 2002:a05:620a:170f:b0:795:4cde:3b26 with SMTP id af79cd13be357-79bb3e1261fmr32740785a.1.1718729942721; Tue, 18 Jun 2024 09:59:02 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:02 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 04/10] nl80211util: add nl80211_parse_nested Date: Tue, 18 Jun 2024 09:58:48 -0700 Message-Id: <20240618165854.113598-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a nested attribute parser. For the first supported attribute add NL80211_ATTR_SURVEY_INFO. This allows parsing of nested attributes in the same convenient way as nl80211_parse_attrs but allows for support of any level of nested attributes provided that a handler is added for each. --- src/nl80211util.c | 37 +++++++++++++++++++++++++++++++++++++ src/nl80211util.h | 1 + 2 files changed, 38 insertions(+) diff --git a/src/nl80211util.c b/src/nl80211util.c index 4a402e2f..0076aa51 100644 --- a/src/nl80211util.c +++ b/src/nl80211util.c @@ -193,6 +193,20 @@ static attr_handler handler_for_nl80211(int type) return NULL; } +static attr_handler handler_for_survey_info(int type) +{ + switch (type) { + case NL80211_SURVEY_INFO_NOISE: + return extract_u8; + case NL80211_SURVEY_INFO_FREQUENCY: + return extract_uint32; + default: + break; + } + + return NULL; +} + struct attr_entry { uint16_t type; void *data; @@ -297,6 +311,29 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) return ret; } +int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...) +{ + handler_for_type handler; + va_list args; + int ret; + + switch (type) { + case NL80211_ATTR_SURVEY_INFO: + handler = handler_for_survey_info; + break; + default: + return -ENOTSUP; + } + + va_start(args, tag); + + ret = parse_attrs(attr, handler, tag, args); + + va_end(args); + + return ret; +} + struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex, const uint8_t addr[static 6], uint16_t reason_code) diff --git a/src/nl80211util.h b/src/nl80211util.h index 6f7b9eab..d966e049 100644 --- a/src/nl80211util.h +++ b/src/nl80211util.h @@ -28,6 +28,7 @@ struct band_freq_attrs; struct handshake_state; int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...); +int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...); struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex, const uint8_t addr[static 6], From patchwork Tue Jun 18 16:58:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702765 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 471DC13AD22 for ; Tue, 18 Jun 2024 16:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729946; cv=none; b=WYKHqOCgIoX/2ydH7C4ELg/zahilCcE3IFAMzQt3uWjeBo/zLO6J69aDgRhq44wKl6CsXRqhITNh6zc1Wn6kIKh54t0LDPG/LfyAR10PIlZIc4pWLi9xapoBKeFz7lx843Hx0vRqIMjNztYu42flLYgJbvpcXsusQRQcRrokNLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729946; c=relaxed/simple; bh=Qi4p6aQevwnNAZ9SyeVDIQTjS9ss0P6raApIZwur9Bs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K5b6GmfRvVP4bJXb8jV8uSa3AvoJkuU3bkTntztRH0A8Vvu5mecwf6qvlRd3ptPGqJphBPpnT8eJhZOKF46YuANyObmxEpMxkRkZAzT0U+DoUANtVU/wHlIHZ+fUQhZJvSEJWUlzUxPvl71Tk7Jx86t383p/25l74WoObwc2/yY= 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=ikVF168h; arc=none smtp.client-ip=209.85.222.174 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="ikVF168h" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-797fb0b4832so280211585a.0 for ; Tue, 18 Jun 2024 09:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729944; x=1719334744; 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=wPGwI/L7oeCcd5nppSf7suc+fUaEOGrTT8KkHeDu7tk=; b=ikVF168h7fQHJhI56UC7fL+x9nf4V8h3GhJOXEnRNwHYWClZacpq8ymdxneqkSGdJU a+NOo8IPUnkz/dY8b9yLN0p6SFmQrxcauLYyV4Lsb7/2oMwdJaeaamGXmcN6bqsidkaK GtOsPk7Wbk3DcjNI44i9SJL/AKIs5e0QJxDCoG6W3R1gthZHnxsKWj6aStl/MQPVNflx GwYiJKU1aLlNG674Pl6OIKqquftXAtpxD/llJGibdG/nJzilrX48U/BBK3kSVCk6XwU+ tNLkc1Ddi9ldGCfgJzAKvFvWW7tB2oJ/Qz0BYurNOfc4l+CaaQd4K6C7nK/eZAcqAHa+ LwgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729944; x=1719334744; 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=wPGwI/L7oeCcd5nppSf7suc+fUaEOGrTT8KkHeDu7tk=; b=r9OSdVusuP6jDCXmNIX1rH4wECKil99LI6RZwxo5AymQzLNdRtlKdmfcBhKOdMdiRY bBYJpch/DlDKzxaIFE+gaCA3BbRaF+flcSxESXCMm1XvitgjREexSYpOzLJCXkCEzcBb XRYopWVWppou7FUqk+4gkXUG8yTwG702sA+9gpvqtfOlNXAQzCBTwKsxBp5GWJfaQced +xMWUtnbYss89FlNqNm8jmu6bmpG0KnPgC2nwQHQ4I4kByoGJAz0MI6/DSUF7dbv8ZPS C3DC9KY9ZNTNWbvTr3wWNXngZ/nAYfKv5C79Dc7g0KneNmD5hdtA8o4cF0IKJ6EFIrLx fBsg== X-Gm-Message-State: AOJu0YwpesipIIhfz6EE+Nopdd3S2mHTicMP6rD7KfwvdTLeYo8G5vIT u9oQwIZnQaGqcWASkzRNkvYprS6pCigs0LygkDmEjFJfgqzh943nAiMyDA== X-Google-Smtp-Source: AGHT+IH7XQsahiuGxsFRzM+TKq0UXCafNxymm0nuDaknRS5oebi3k1/7EXA7725kJxfm26XV+HvEaQ== X-Received: by 2002:a05:620a:1918:b0:797:a485:28ef with SMTP id af79cd13be357-79bb3e1240emr34202885a.8.1718729943950; Tue, 18 Jun 2024 09:59:03 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:03 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 05/10] nl80211util: add ATTR_SCAN_FLAGS Date: Tue, 18 Jun 2024 09:58:49 -0700 Message-Id: <20240618165854.113598-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-1-prestwoj@gmail.com> 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 0076aa51..ac4ad223 100644 --- a/src/nl80211util.c +++ b/src/nl80211util.c @@ -159,6 +159,7 @@ static attr_handler handler_for_nl80211(int type) case NL80211_ATTR_WIPHY: case NL80211_ATTR_IFTYPE: case NL80211_ATTR_KEY_TYPE: + case NL80211_ATTR_SCAN_FLAGS: return extract_uint32; case NL80211_ATTR_WDEV: case NL80211_ATTR_COOKIE: From patchwork Tue Jun 18 16:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702766 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 6D3CF13AD12 for ; Tue, 18 Jun 2024 16:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729947; cv=none; b=UhhRVCvIQfym1PBeN1iw3YP82p2jyTLeW9cQ1Is3ETYPH+Ri9xU0THcwxgZ/6VHkjcAAld5Ca1dDKTJND/0/LYyvSnPGgJJMsZ4pYt8/c0vsNayVubGQIN3CeW9Tz+RGkfdz3MEQegqcB7L9EgWNjSwJbRL8njRqCJvtdc0yVJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729947; c=relaxed/simple; bh=E6VJEGcoDypDNdJ7/6LEmaXOwPtzyEzcxk0LkzmsiCc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZAPP9fk8mptANH3DUqw4aATl4ELEtFvSdoX0OzUNUWOFHPDEOxTQFU98ru8r+geBHcjXrqQvFcSxcszfTioL8e/BoWSmNA40WRF8ScSLxJbfCIZxRwPGN68QdzGHWpP7MYxwJNqwrf2lFWkXqPy1uhAz3dWWkOLra47GfRUndGE= 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=CYwNETzJ; arc=none smtp.client-ip=209.85.222.181 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="CYwNETzJ" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-79776e3e351so416737585a.3 for ; Tue, 18 Jun 2024 09:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729945; x=1719334745; 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=cx1DC9zlmmqSGmQdQNzX7sLJh32HVnFTeWUrU2KnRns=; b=CYwNETzJqVSdLgzHNbCWw6YHfbUfQhyiOQsljQo8/JhJjr02gwodB9WMvP5mpIUcBi Z7C2UovEK90MHs7ZPcEH1XclSnKz+hfA6EPR+yHqulLcAlAfU+IGhVWLFSPZA06u1VRj vkW67uZl0+PypMe3rl/u/oL8fV/LzQkUVgc/TJTzoKHSMRUO4zPgR6lo0Yjdy9VgWFuf luWs5m6vpntRutvPdqzdrGtB4Hu1WOxX2dlmJ1VJCxDpU+3pTVsKOOEgiyrBVDXCpQ+u T52wC3tyHGI/hwoSI2jVBB9QZHZpqeC50Hy/UYq8HV1BVoyF1DHNSx/5A6GBY/WYtjmh wOKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729945; x=1719334745; 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=cx1DC9zlmmqSGmQdQNzX7sLJh32HVnFTeWUrU2KnRns=; b=ohPcw8jZrXnhyaXIB8yJZ7a/+H0W0dA48dQoS0WWRiVyyTJ2hOLBORJDTc8Bao8hyH PrWK2CIT0lp7a86Rmj4WxNnxGIQ/M2yviQ1bIGElPG3u7yhaTLXY5YXl5+XYhaBaXxGN koACvRa/35uJ9FWHB3fhpe+FGRyCCPCuJBi9EwvEy1+YC6gOKHZsM9QUX7+POIieRzNi SPM5Sal6Mkn9Q/S1JyeF/ocXJU393hxemMqP4ntBD2LVCGrgI651/BYTlj3rwuh/VA0b KBWeWVjWWGpplpbRXz/HMvY9h+0hcjyaA/knv5NiJDw9JxFWJZ1dxOaJddP3FRQ+oue2 Ywbw== X-Gm-Message-State: AOJu0YyXMUrm3g/3qs5iYPD57VJSJDOliaM36OIHnLbWBhykGJXi70ru db59pgOZ1J9BZGqi84DTQX0zlpqF+aetrhaphfmYuYDtaQ0M22W7sdoDmA== X-Google-Smtp-Source: AGHT+IGP719tYP5DrlodxgPONDBYFjIhdluraS9731t6W62DOua9fv/xRYe+ACmrEA+EbsbmFzBsCA== X-Received: by 2002:a05:620a:4153:b0:795:56aa:c8b with SMTP id af79cd13be357-79bb3e57dfemr26954885a.44.1718729945154; Tue, 18 Jun 2024 09:59:05 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:04 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 06/10] scan: fixed flush flag parsing Date: Tue, 18 Jun 2024 09:58:50 -0700 Message-Id: <20240618165854.113598-6-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Parsing the flush flag for external scans was not done correctly as it was not parsing the ATTR_SCAN_FLAGS but instead the flag bitmap. Fix this by parsing the flags attribute, then checking if the bit is set. --- src/scan.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/scan.c b/src/scan.c index d3f0ad31..55d560d4 100644 --- a/src/scan.c +++ b/src/scan.c @@ -2021,16 +2021,14 @@ static struct scan_context *scan_context_new(uint64_t wdev_id) static bool scan_parse_flush_flag_from_msg(struct l_genl_msg *msg) { - struct l_genl_attr attr; - uint16_t type, len; - const void *data; + uint32_t flags; - if (!l_genl_attr_init(&attr, msg)) + if (nl80211_parse_attrs(msg, NL80211_ATTR_SCAN_FLAGS, &flags, + NL80211_ATTR_UNSPEC) < 0) return false; - while (l_genl_attr_next(&attr, &type, &len, &data)) - if (type == NL80211_SCAN_FLAG_FLUSH) - return true; + if (flags & NL80211_SCAN_FLAG_FLUSH) + return true; return false; } From patchwork Tue Jun 18 16:58:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702767 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 9C7C5132492 for ; Tue, 18 Jun 2024 16:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729949; cv=none; b=miP0LzResRX/szHQvDhZd3Ve7R3/iLmgqlCKfMhSOb1QXRLoiqSeXBpRNqSVOrQthfl06PkyrMIx2Lz6jp42lZ5xI5PD2zJz8AXT4iAvH45oacqXYUIbEjkbsehwzxpdKZvCo69yRuPmqGI1DLwGGgD5z1dqfC8qXAIi4D9tbaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729949; c=relaxed/simple; bh=3IEsrY88d6tHZcrsaVSfzv/mQCfcsr4KGigeFa3Kg0M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PiCrYc85k2XQUxRogFZwfimlTD87xwMet0ebyXM+I1AAqIjyXUq+uTteB8J1+kgT4WRcZfk/UgB0nA7yuf6w9z1Zk+08Ah+cjNY5t8NymrgXc52RGO3YtdA4n+D6XqFzxKu4+DdcpxUG25Smc2TiO0QR2O6Sf0ieeRTIqQUt+Ow= 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=VcU8jRI3; arc=none smtp.client-ip=209.85.222.181 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="VcU8jRI3" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-797a7f9b552so373834885a.0 for ; Tue, 18 Jun 2024 09:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729946; x=1719334746; 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=VTeXdgdUGKZQc2ceKeiP2hzPvKWpUvuiSPcGMW871oQ=; b=VcU8jRI3QQCMJwl87O02NfUAOq49Q/fSpOA+iDHHyH/FEv1gmz6ElmS9rzRveboh5E cmq5MvWb3Gowmsl6V9r0P4HQLpHD/3zuddWiEiAB1Bv+eAlR/6XRxHsn+D61E+Vw+2gX aL5eQeYT+50p4lGwrmd/143BK5dZ/UXIKZvKX0m+KnFw/vwiQddQxC8we8QGI68TxLsp Y9jZXU0QxyCLisoyP2giyRBH4rcUByxQBO8iQFtCEGfbQuzwctR6gmXmHZ+q085kqTZ2 rk2tx4eRY1xJsPMN7YRXiqkF1jxtYev9GvNEEUw2AcPmnpO2lb+ydyprzOmjinuwM3Kl O2KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729946; x=1719334746; 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=VTeXdgdUGKZQc2ceKeiP2hzPvKWpUvuiSPcGMW871oQ=; b=FesLbeOJuAhUHiA6jHX3GnjQsobwUHNMbJS55TMzqn98r/X4Ilh+DIxIaZWZgIUKg4 ME4aeEmO+Kgbb4QenFDCSo8bGveMaQDpKuXY+Niwk6EF7j1kWC2/T4XTep+D7k2rcV3T vuqCEu1yGulMDq6Wfe417zdw2tup5+foTk2Fk/OxWqTeTeo6wRhwm+9YhQq7Dux5sofJ yFWvkPxUQLppCmh54djedQwj7mw5v8X9dK9CG0rdx716J1hnuAcsUqGxFXZXMFS7B5rT 7hIPU9cvEO0xwJUvKbw9GPEA9IJ5+TxPQ54zBJMRceYHGOCvA5IWrjL27aAnrS767vZi AShw== X-Gm-Message-State: AOJu0YzRuYjMr20DfQW+ItZk76exSxpLO5YAZRSaAVfW0mBDx2UxBwnC kLXLzvkETVzD2h4piUXGOnCd06DVK5hI3hz0uyjom0P9ibh02gZYO2R/4Q== X-Google-Smtp-Source: AGHT+IHUOj6cdRmaaG4vrekFjiWlZN1rYHZOpgZ8U4p9sEPDV0ZOiZ9QzIuijTK4vW9UqidQuHceyQ== X-Received: by 2002:a05:620a:4614:b0:793:1a75:177e with SMTP id af79cd13be357-79bb3ed48b2mr29226085a.50.1718729946321; Tue, 18 Jun 2024 09:59:06 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:06 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 07/10] unit: add simple test for nl80211util Date: Tue, 18 Jun 2024 09:58:51 -0700 Message-Id: <20240618165854.113598-7-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- Makefile.am | 9 +++++- unit/test-nl80211util.c | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 unit/test-nl80211util.c diff --git a/Makefile.am b/Makefile.am index 0ef4f965..0c152216 100644 --- a/Makefile.am +++ b/Makefile.am @@ -433,7 +433,7 @@ unit_tests += unit/test-cmac-aes \ unit/test-ie unit/test-util unit/test-ssid-security \ unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \ unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \ - unit/test-dpp unit/test-json + unit/test-dpp unit/test-json unit/test-nl80211util endif if CLIENT @@ -582,6 +582,13 @@ unit_test_dpp_LDADD = $(ell_ldadd) unit_test_json_SOURCES = unit/test-json.c src/json.h src/json.c shared/jsmn.h unit_test_json_LDADD = $(ell_ldadd) + +unit_test_nl80211util_SOURCES = unit/test-nl80211util.c \ + src/nl80211util.h src/nl80211util.c \ + src/band.h src/band.c \ + src/ie.h src/ie.c \ + src/util.h src/util.c +unit_test_nl80211util_LDADD = $(ell_ldadd) endif if CLIENT diff --git a/unit/test-nl80211util.c b/unit/test-nl80211util.c new file mode 100644 index 00000000..34a7c2a4 --- /dev/null +++ b/unit/test-nl80211util.c @@ -0,0 +1,63 @@ + +#include +#include +#include "src/nl80211util.h" +#include "linux/nl80211.h" + +static void test_parse_attrs(const void *data) +{ + struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE); + uint32_t ifindex = 1; + uint32_t freq = 2; + int ret; + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); + l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq); + + ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex, + NL80211_ATTR_WIPHY_FREQ, &freq, + NL80211_ATTR_UNSPEC); + l_genl_msg_unref(msg); + assert(ret == 0); +} + +static void test_parse_nested(const void *data) +{ + struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE); + uint32_t ifindex = 1; + uint32_t freq = 2; + uint8_t noise = 3; + uint8_t noise_out; + struct l_genl_attr nested; + int ret; + int ret_nested; + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); + l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq); + + l_genl_msg_enter_nested(msg, NL80211_ATTR_SURVEY_INFO); + l_genl_msg_append_attr(msg, NL80211_SURVEY_INFO_NOISE, 1, &noise); + l_genl_msg_leave_nested(msg); + + ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex, + NL80211_ATTR_WIPHY_FREQ, &freq, + NL80211_ATTR_SURVEY_INFO, &nested, + NL80211_ATTR_UNSPEC); + ret_nested = nl80211_parse_nested(&nested, NL80211_ATTR_SURVEY_INFO, + NL80211_SURVEY_INFO_NOISE, &noise_out, + NL80211_ATTR_UNSPEC); + l_genl_msg_unref(msg); + assert(ret == 0); + assert(ret_nested == 0); + assert(noise_out == noise); +} + +int main(int argc, char *argv[]) +{ + l_test_init(&argc, &argv); + + l_test_add("/nl80211util parse attrs", test_parse_attrs, NULL); + l_test_add("/nl80211util parse nested", test_parse_nested, NULL); + + return l_test_run(); +} From patchwork Tue Jun 18 16:58:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702768 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 0800613BC31 for ; Tue, 18 Jun 2024 16:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729951; cv=none; b=Y2t9AcXcZVNPfRNNy1TeW6cG6tUeLoEX/wYkWcmXzWUWd863afNTx4URtxqpXMvQ9bU5Ve/Zmw0Q9bM+3ydpgPh1JCm2ZLqFPKniMZvMuzuPcR/W5CQWvSxhjccMWeStt1d2/jkxffeA/JKRW/SUpZraqniuNOFntumNDHn07aM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729951; c=relaxed/simple; bh=1f0d615K+oWHY4fZX+gIJLmlr8SAxj4iBQJBduSXNCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r59sBwgXH2wMuIOScsHOSl3KLH/u0msQQo5GudQZgtxvEI1Xl/+pDvSZJ8AASF+/ZSEq0AXy3N59p5wJ0W0yzkq21YOB20FgjvZ82aTlImZfpTfsgN3toUGAZogCJgNdQcmcYlMJkGy2OUB+jFgI3UUROC2e+qfN1uwSRUvp3Og= 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=Kwkc38ky; arc=none smtp.client-ip=209.85.222.181 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="Kwkc38ky" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-797e2834c4eso2073085a.0 for ; Tue, 18 Jun 2024 09:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729948; x=1719334748; 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=lbN+oW9si7tCvQ8TmgJ5F2whYRufSAGMcQWP4dm6WT4=; b=Kwkc38ky/gGqkCeA8ZCzNv40FMOfIWNqRoLnMgC9nlAmXAbsZaAZCkPzVCtbD1f3jY O9qFEVavfu0sh6lzmj2GVHlcz4gvZYWcJCjGNt8/yLeqS6N3iqK1PWDFaSzBRRG9B58s +TEP+t0aqG+UUQUMOkawLK1fmwZXSBdK3vzCfxwQf+bq8XeOCOkJGV5L6SEMOJx1uoix kqFIuc2ARsW3SZPV80pwH6oqLllgcmkz7LAQXRIo1tf9E0hmj1267MqLgsTkX96RmFSU 4H+aihQ1OgBcLzJeHxTag34JQpiUhpZ4e3NSxkrbPSTBYBfA6BtrJq7USv0Ql4T4sHU3 i7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729948; x=1719334748; 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=lbN+oW9si7tCvQ8TmgJ5F2whYRufSAGMcQWP4dm6WT4=; b=AUGBiTAJlaEz9q2peuDyk54CQf8whoULILtbi+PSTJDswkUOUjrGUgPDeEzY+8KeHw T8qaQItT4nR3MhzuxTLkI66KL5Snwh+k0co6XjaVma3lojluZnvZiYR092442WRicqeA usEDnt36HUREA50ZFoHMY95u8C0PEibO4Ttu+0yy/WGuCHelvpH+mVNuiMBxVHIPjPyb mZJ9qH5k1HiQMoHy1L2hfj4It9U/pLVGjYr3UAjVt+mQq26ZCJ3rG8XmcscNgKgHvuJQ wAWrRoZ0e4b5lhTLiod0gPoo7562M367sYOORoSzYBw7kLNntpyYfk1WD7FXdr2iEj/I 0qQw== X-Gm-Message-State: AOJu0Yz2E4s65FrRcELS9d09uNEe6mq2++kmCbIwZxGwX1tQ+7mBi4gE cAntzSttVJMZeHGKrNLMAPLkF1wtCw59RxtSsXS1uNloQNMN07U8UsG3xg== X-Google-Smtp-Source: AGHT+IE8Y1AtN2NoFYMo/gPJu9JUH8WOmG/2KWivkDe/fR/a6OgeVP26HtLCQNer3H9b/vWkQGFYwA== X-Received: by 2002:a05:620a:4141:b0:795:4e67:1ef5 with SMTP id af79cd13be357-79bb347ce14mr70563885a.11.1718729947525; Tue, 18 Jun 2024 09:59:07 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:07 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 08/10] scan: use GET_SURVEY for SNR calculation in ranking Date: Tue, 18 Jun 2024 09:58:52 -0700 Message-Id: <20240618165854.113598-8-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-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 | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/scan.h | 2 + 2 files changed, 151 insertions(+), 7 deletions(-) diff --git a/src/scan.c b/src/scan.c index 55d560d4..76ea379b 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,88 @@ 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; + uint32_t freq; + int8_t noise; + uint8_t channel; + enum band_freq band; + + if (nl80211_parse_attrs(msg, NL80211_ATTR_SURVEY_INFO, &attr, + NL80211_ATTR_UNSPEC) < 0) + return; + + if (nl80211_parse_nested(&attr, NL80211_ATTR_SURVEY_INFO, + NL80211_SURVEY_INFO_FREQUENCY, &freq, + NL80211_SURVEY_INFO_NOISE, &noise, + NL80211_ATTR_UNSPEC) < 0) + 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 +2081,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 Tue Jun 18 16:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702769 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 6931613AD12 for ; Tue, 18 Jun 2024 16:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729953; cv=none; b=UcgDm4mTUk7tNVtt6XUKeOz0r3wgfR/TnlH6W4nSdb69/WIGRZt5vHb/vfl/I1mqbQcW6moOmt3kBWOAxOFLnTCPvD4u6c3/2nJHgClUuFKzrYFynVTiAl3s6Sqk3hkyT40nOwBmexNHrOd71t0VPHCeSdcYcI5Q3/R4U5eTHrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729953; c=relaxed/simple; bh=d4aQiARAjHBxBw3HNTLNiEesJ/4Ik0DfP7TPhYRIqYw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m/Hw3SoQlDRG622dCZCxuJ7ykteH6+r2puZY22hbnUKCmEm7F0w7h8mTJ1JSnT6JsEWS5OQ+R0PYNorhdYW7QnFO8KK77doBSQZTOXIERcykNVyl0U8RqdVMvY+fkRao53NfYpjPLJoLZPI17zjJjGcS8MjwBBzK23aS1MIbfro= 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=mh8bdcrN; arc=none smtp.client-ip=209.85.222.181 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="mh8bdcrN" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7955ddc6516so400077785a.1 for ; Tue, 18 Jun 2024 09:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729951; x=1719334751; 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=YugUbaB++Sy+7ZvVbpCjBKUT8aoIJZhlP/HBkUlkHjg=; b=mh8bdcrNMvRSHnJ7LeEKW0OAaBPOFDCUqet+PWAJOILBiQYFSjgOfT6qiP5BRayiFN 08yZ+jGq+uzZElPxbiiBMpoLfdpwAtDRPazLvJaLt7R5j34OGfRpNXme2ESG0EqR5JUB Usl6O9BaL/QjkwkMMvqtnZ9OTCS0i9+A5Bw2ZEZQ8S1mipYWX+4CHV2twYD8brSskQZX ni2tj/feKJTnsQG/wd+I6JUHSecCG2JLaeUlf+yWP8i3n9zKzs4bp5opNuHJ27MRWz9F jQsODQSWFYF3VybdDWpbSY1M+RZwVyoctXXmeF1G0vtVMCWh0kIirbHKtSuT2iY7WRjI FH6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729951; x=1719334751; 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=YugUbaB++Sy+7ZvVbpCjBKUT8aoIJZhlP/HBkUlkHjg=; b=PWmUfiuyH7Qm4sh/KFTN+M2g2tj1CaoPLzQM8GCHSQ86oOO/k0jLN7QybNfxE2FtjP I4pKT7KvoF07HKrKzrYsY/tToYynP8beCTu+Wi9RVg7FTlZTXAM8XZAJXNIxDdzkBPdd ywwJFmVNhXFrdk5Tsfjam7cWol7psDH17U70gGKEriSKuhVzfBvaWdRRcrf00C2J5S0S 1P/p18MHmdRt268w01fupksm/h1Kr6ZuPqtAAQHkj/0G24lQa80V8988qhlOr7AOOgvE eUBDRbUU5MBBN3yLDDdJvwhxzlz7/f8sKWb+Jvy7S67tZjJE9+tZM8rCTjMvs0F6CErr 7Zwg== X-Gm-Message-State: AOJu0YxY/QZ+5gJHTV6Kr6nxMlltnANP+tkEHgikjGq3xCFNjwbND8Z7 BX/1uqCPjt5UQZxvN3CUxemS4vsd6w6x2PvO5pxQGkx8AmaD/+MPN3Al8g== X-Google-Smtp-Source: AGHT+IG7AUVQnRTafTcFJODn51tADr5q8C9bQNFU+yY6c4R+lXU5HuLikr+Lon/KF1dlSpe0aTXZ1g== X-Received: by 2002:a05:620a:4506:b0:797:8ee3:9f01 with SMTP id af79cd13be357-79bb3e602e0mr25128785a.34.1718729950113; Tue, 18 Jun 2024 09:59:10 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:09 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 09/10] scan: add flag if BSS load was advertised Date: Tue, 18 Jun 2024 09:58:53 -0700 Message-Id: <20240618165854.113598-9-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-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 76ea379b..5091ad77 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 Tue Jun 18 16:58:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13702770 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.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 8A42D1CA80 for ; Tue, 18 Jun 2024 16:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729955; cv=none; b=B+N5/ds/J5Ygmv6A3Zdaza3NYT34YoJjPQ4LVS2A10zhILxN4qX+VAi82jVu0/Avpgvo9Z/dY6XNsEiPMDD9+1snPOHfIMhg7FWaLm2PGZL09qa+1RgNeuC3frveBTtZ6f/Wdq3bT/2djVRfPvICi/UY0EOUAg4sVcrVNliGRds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718729955; c=relaxed/simple; bh=uoLh7ZThrih6ndfpJ1BfPHhyxIzr+KFOvg3V89yDoAw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eGrk6lvNVbI475Pe7BEly3NUmqRfU4BL9LU5trTCNIbBNAMPRGToS/jFd26t28ry71BKfsjO+QOPDfK7XQqGFwM4Fcg7scilA5fZMgDBp9uG3ag01OyrxBCIgR8Je+4xzOp6mi4EMXrr49M4dqxoJfzglBMeENKgTvYsbFrmhPU= 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=lpPyJpS5; arc=none smtp.client-ip=209.85.222.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="lpPyJpS5" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-797b24b8944so533297985a.0 for ; Tue, 18 Jun 2024 09:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718729952; x=1719334752; 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=lpPyJpS50Uz3MGi9i0AkY4Iw3gIhWfafFPX/z0J5FXaABpi7pBulde/v9+i3resmo8 z9FV1Ri1V45feCnqhzp7F2qtFJJzFxEEdJoUIndBde5A3XpBeSrtPKAXexkOBEE9+MT5 jVJd2TDG2LzoxJ2IdvvYppu3qrxMHOkd05Cu+BsIkoF/mP8W5XioUBo64ETvcFxF0RA3 Octmt/pjdMeNnw+SXiMEG4QYx9IH82KWn/TuQL9hfZxY2IqKn2U1fK0v7Ny6GB/Ra1Ye 9FxO7jxg6vUdIqu6VYtQndcHawqNg33MFcKBLntDOK/vista2OXTK83dNcCwQDZoLaPS 7xqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718729952; x=1719334752; 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=GBpgKOfMD7Txt9pIRRU5HrI0RSK9ga6hnRY7F4c2yiMtA4QarjhTe7PQ7pH60FS6i0 I/ro+gqwPGTRkwH+bPe3tpX8pK+1Iq2sQXPGYtfTZQ1pPrBUfApC3QcgMfdeUCk6Qcxw /VI63EsZfHyVT85pFR16TpnPGipJZU1OP8/PETDozyz7iRacoE7f4zXPRj0jvXQ0ApOM n+aVq+TP2bdoKsU8j2ORYSxnX0dP5nMWyBJEX2vVmxe+Ig3VgNmv1lp8FSOLNeMwtzcX yVn0Jbi9IxoLOSbXTs9K3qEyFAcvILjd8nxrENEHq0CBaiqW6DZ+RWuWlFowJXA9e9om bmPA== X-Gm-Message-State: AOJu0YyZPHvMN7XMwpX3sUtxvO0hL3BUh/ETuNlvtrEMyA3lQ5/aC1Hr ATK3j/c9wnLem1Z59MqP3GBfAWzCy5T0XEcQEFcepeqGlZ81Ml0UnX5x2A== X-Google-Smtp-Source: AGHT+IGmBOJNqxO72EZV9p4S5TRPuZiiMR2IHOLBMW7EV5GgUEriIzgOFXf3NhV8Kj8CF+087VIbNA== X-Received: by 2002:a05:620a:3906:b0:795:22e7:6fe9 with SMTP id af79cd13be357-79bb3edfe78mr28987485a.63.1718729952264; Tue, 18 Jun 2024 09:59:12 -0700 (PDT) Received: from LOCLAP699.rst-02.locus ([208.195.13.130]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798b49e4c82sm533688785a.88.2024.06.18.09.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 09:59:11 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 10/10] station: refactor the printing of scan results, print SNR/load Date: Tue, 18 Jun 2024 09:58:54 -0700 Message-Id: <20240618165854.113598-10-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240618165854.113598-1-prestwoj@gmail.com> References: <20240618165854.113598-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))