From patchwork Fri Sep 11 12:59:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 2303249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=P+qFvuPM; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=NAov8UAq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hhVbJ6ky7z1y1f for ; Sat, 12 Sep 2026 09:08:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wsy2XJf9MCtdley6MvIvyMyJrFUP/4dcoUfpMTDfTCo=; b=P+qFvuPMV9Nzit JwB5Rriv2CMfIRvpYw4yYOp/fCqoUAZtRD5jq3kdG5DDLwI/yZvUTVndnWwPq6IoTnRgZLSAQ6CHv RKM5J8JgYC37BgCn1xZXo+CO98YAc0P3dZTQrYnaAinCyiXglEYa0ThGPZz/09ea27IrAeTyUILHP AsApohoiVquqjK61ALJJuEMGfbQRIinfUB9ci28Nq45KaH9Ab1rQKfX8YTZ7EnPIrccoSa89dwd0I Qn0QBI27Pl3KJK+DlhLJbAAvn8cbvCh7j3fChEe0+UedqIh4RBkexuWvs6ncGhrlY8bdsioQIjo4M /49mmHVPsDvh86dDDZfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIe-00000000KUN-1CIK; Fri, 11 Sep 2026 23:04:52 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIa-00000000KRq-24pc for hostap@lists.infradead.org; Fri, 11 Sep 2026 23:04:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=+hGjDqVouUnC655YkHtyAXabZmts8zdwWdF/uOdb/W8=; t=1789167888; x=1790377488; b=NAov8UAqE3iB6ODymmnbM64d+s9h2X/30C9rxdM7Zy9L+Iq 2H6Jg8lEeVA5MG8pxso3gz6eSC/xoGglZJHNor0NJO2btNwMhJif2f6z7QZqL5ylt+GPIpeCI5pC6 qikr5XKxQBS4sytaem0KTFSPUe3ochiITM9Rd/T/GbC+as6mHdv+twSNoAmeEZYuAD72gCYcCKQFs m4wwSmvtdkbwm5rOyunsWSqwDYNwtJlm1QdNjm7NnWQ+T485en1zqQ9cE7QYjNBb+afQaHz2atBNs A3vq6Cd/OxU2FeolGT2r1w6LpG7pbAXMWFOBsBI4MILDZ2oSHWtMR9exNf8FTgig==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1x5AIW-0000000CP3F-3O3h; Sat, 12 Sep 2026 01:04:45 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH v2 1/6] hostapd: ctrl_iface: add commands to get GTK/IGTK/BIGTK Date: Sat, 12 Sep 2026 00:59:49 +0200 Message-ID: <20260912010440.134710cd120e.I91a1d4893862b7f2e04707626ba62c2216e835c9@changeid> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911230440.2087889-8-johannes@sipsolutions.net> References: <20260911230440.2087889-8-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_160448_542149_6BEF3376 X-CRM114-Status: GOOD ( 12.05 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg For some of the tests that the relay module enables we'll have to have beacon protection, so the relay will have to recalculate the MIC in the MME. Add testing commands to get the GTK/IGTK/BIGTK from hostapd. Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg For some of the tests that the relay module enables we'll have to have beacon protection, so the relay will have to recalculate the MIC in the MME. Add testing commands to get the GTK/IGTK/BIGTK from hostapd. Signed-off-by: Johannes Berg --- hostapd/ctrl_iface.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 6c197c36e1ec..c37e9cec5989 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -2575,6 +2575,39 @@ static int hostapd_ctrl_get_pmk(struct hostapd_data *hapd, const char *cmd, } +static int hostapd_ctrl_get_gtk(struct hostapd_data *hapd, char *buf, + size_t buflen) +{ + if (hapd->last_gtk_alg == WPA_ALG_NONE) + return -1; + + return wpa_snprintf_hex(buf, buflen, hapd->last_gtk, + hapd->last_gtk_len); +} + + +static int hostapd_ctrl_get_igtk(struct hostapd_data *hapd, char *buf, + size_t buflen) +{ + if (hapd->last_igtk_alg == WPA_ALG_NONE) + return -1; + + return wpa_snprintf_hex(buf, buflen, hapd->last_igtk, + hapd->last_igtk_len); +} + + +static int hostapd_ctrl_get_bigtk(struct hostapd_data *hapd, char *buf, + size_t buflen) +{ + if (hapd->last_bigtk_alg == WPA_ALG_NONE) + return -1; + + return wpa_snprintf_hex(buf, buflen, hapd->last_bigtk, + hapd->last_bigtk_len); +} + + static int hostapd_ctrl_register_frame(struct hostapd_data *hapd, const char *cmd) { @@ -4502,6 +4535,12 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, } else if (os_strncmp(buf, "GET_PMK ", 8) == 0) { reply_len = hostapd_ctrl_get_pmk(hapd, buf + 8, reply, reply_size); + } else if (os_strcmp(buf, "GET_GTK") == 0) { + reply_len = hostapd_ctrl_get_gtk(hapd, reply, reply_size); + } else if (os_strcmp(buf, "GET_IGTK") == 0) { + reply_len = hostapd_ctrl_get_igtk(hapd, reply, reply_size); + } else if (os_strcmp(buf, "GET_BIGTK") == 0) { + reply_len = hostapd_ctrl_get_bigtk(hapd, reply, reply_size); } else if (os_strncmp(buf, "REGISTER_FRAME ", 15) == 0) { if (hostapd_ctrl_register_frame(hapd, buf + 16) < 0) reply_len = -1; From patchwork Fri Sep 11 12:59:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 2303248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=n0oguxXm; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=tyrtAcIh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hhVbJ6hhRz1xwp for ; Sat, 12 Sep 2026 09:08:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fAupM7lRPzcijXEyxQZDhiIFACZFkC+kKyLZmUiYmno=; b=n0oguxXm8dNDpP obYMxEXqJwGkA2SWIxkxnr4Q+QL3jh+UsvV9WuMvXv3SV+PKGwqexLx9Gvc4eXvYNdY85Oi+BZN+j Io8Iho2i4+R+ElAGgJhPqomlqhqNj1Jz35YQNh2Hu4XE9bRnewj0Z2ciabXhjqoLnL/+eqwAaVCYm HHVUf485USSpv2s1p8/cFK/GgBgCJ1QA5MTiHvsBaCqYKV+yuLrr7E23p5fEPwfpzTrKWUBRRLXkZ ZqC3brkNcxOnWiskJ7OQ8wAr/ifLVDGQ9JwYDNj73YhUKyPQ0FaQDo3Z7K59kOa3PuYom0baayiV4 hko5v3Kxcn1i3JxPTFZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIe-00000000KUZ-20tJ; Fri, 11 Sep 2026 23:04:52 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIa-00000000KRr-2XKp for hostap@lists.infradead.org; Fri, 11 Sep 2026 23:04:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=RwcbaOFz5tHHjNt7Pydiqu3BTgwLuF2/9i9j+47wqQE=; t=1789167888; x=1790377488; b=tyrtAcIhIghZo+7pmrKkE8CYQSVQ4VOgt91ULW19lcH2jkx 7gB7/PbtnxHQvk/fLtFT3MSbYmRQ2I2ehYlHMf01W7FBg5ONFkvIhrxMgPcgFYo3zsAw7pKoDZluS JGyyY245p9cRBvA36RG038qgrGYaKY4KQTEruZ0G5uZ5fxyacZqMQSPA6DAqrjDU5RcVBDxXkLOxu aG38UPdCDJCpFxI0drIW9eWndw2LRejoMy7oWnxMnaxDZ42/2z5rV8S56NiGXTU+Ojap2hqcWJ6hF Zghogi8mbxtVYNmBAMvRLGYK8Y9LkjsEt01JLX4cToHmunEmmF0dGHZlLYzCPNjQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1x5AIX-0000000CP3F-1a7Q; Sat, 12 Sep 2026 01:04:45 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH v2 2/6] hostapd: ctrl_iface: add LINK_STA command Date: Sat, 12 Sep 2026 00:59:50 +0200 Message-ID: <20260912010440.f55a67f2cced.Ic8a6681ef4102a46e0d61cfb0ebdcdb311985d8e@changeid> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911230440.2087889-8-johannes@sipsolutions.net> References: <20260911230440.2087889-8-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_160448_643082_15B9DE58 X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg This can be used to look up a station by link address. Signed-off-by: Johannes Berg --- hostapd/ctrl_iface.c | 5 +++++ src/ap/ctrl_iface_ap.c | 19 +++++++++++++++++++ src/ap/ctrl_iface_ap.h | 4 ++++ 3 files changed, 28 insertions [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg This can be used to look up a station by link address. Signed-off-by: Johannes Berg --- hostapd/ctrl_iface.c | 5 +++++ src/ap/ctrl_iface_ap.c | 19 +++++++++++++++++++ src/ap/ctrl_iface_ap.h | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index c37e9cec5989..047aa3d154ef 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -4326,6 +4326,11 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, } else if (os_strncmp(buf, "STA ", 4) == 0) { reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply, reply_size); +#ifdef CONFIG_IEEE80211BE + } else if (os_strncmp(buf, "LINK_STA ", 9) == 0) { + reply_len = hostapd_ctrl_iface_link_sta(hapd, buf + 9, reply, + reply_size); +#endif /* CONFIG_IEEE80211BE */ } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply, reply_size); diff --git a/src/ap/ctrl_iface_ap.c b/src/ap/ctrl_iface_ap.c index 57ec4f6ec12d..223f9601623a 100644 --- a/src/ap/ctrl_iface_ap.c +++ b/src/ap/ctrl_iface_ap.c @@ -587,6 +587,25 @@ int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr, } +#ifdef CONFIG_IEEE80211BE +int hostapd_ctrl_iface_link_sta(struct hostapd_data *hapd, + const char *txtaddr, char *buf, size_t buflen) +{ + u8 addr[ETH_ALEN]; + struct sta_info *sta; + + if (hwaddr_aton(txtaddr, addr)) + return -1; + + sta = ap_get_link_sta(hapd, addr); + if (!sta) + return -1; + + return hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen); +} +#endif /* CONFIG_IEEE80211BE */ + + #ifdef CONFIG_P2P_MANAGER static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype, u8 minor_reason_code, const u8 *addr) diff --git a/src/ap/ctrl_iface_ap.h b/src/ap/ctrl_iface_ap.h index 4de140844f0b..e2add32570c6 100644 --- a/src/ap/ctrl_iface_ap.h +++ b/src/ap/ctrl_iface_ap.h @@ -15,6 +15,10 @@ int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr, char *buf, size_t buflen); int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr, char *buf, size_t buflen); +#ifdef CONFIG_IEEE80211BE +int hostapd_ctrl_iface_link_sta(struct hostapd_data *hapd, + const char *txtaddr, char *buf, size_t buflen); +#endif /* CONFIG_IEEE80211BE */ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd, const char *txtaddr); int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd, From patchwork Fri Sep 11 12:59:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 2303251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=r9F3HGdA; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=jWh3k68p; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hhVbT0yPkz1y1f for ; Sat, 12 Sep 2026 09:08:53 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RtbyekxwSbnAhYRduABS2pKXALjjtF31fJ6gbBYlCes=; b=r9F3HGdAqA5Lkp p0LW994/e6FFsZrpIzzpsjFiWG7VYP78+hY9pR+ET+SLJVQAz88NdCDSOshGuUTfRsFcd/TWkIM23 dptfLVuq6D4myWFGyjClHygwBQVOjeGpWbCocMrfED07QwQ26xjYhtHuaITnoR396qUsqXRedOsup UcNfbz+llry/1QyvY50FEBCzqkXZ3WWadqi4rZmWlPIZecfpCPn9hiaVQgZn5TmMPoe9AVlGITMmh s7tRVF5Mi8NAS4MBxVAZKZJlAD82g2ieOKtxQK3kFHtr+LaY/gS9DqlTmOacRuF5d6qJpuDh2LqKG WluDh59aSdCRuoHqKh/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIe-00000000KUi-2fbL; Fri, 11 Sep 2026 23:04:52 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIa-00000000KS4-3ayL for hostap@lists.infradead.org; Fri, 11 Sep 2026 23:04:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=d4ncpnoega6JQKJPsXrgXCT3dwPbIAU9PZXx2tnwI/M=; t=1789167888; x=1790377488; b=jWh3k68piunwZkyGDZW7GQEXH2lYYAfNiXrD7/QWqs0Gv1b tlEKbPRccRd78i3eWYybvtagRrSwwG7w80+dqRN9VHeO1zE+QqdSopk/KZA0Ne0KfeBK4JrGtMsfB noz3HtptqIPa14u34VfFnadw7GCyOr+v/TOHe2ZdF9LJT6201Q9wzt0UhxcbjGkh9oNJEDCJp33GF B0kjcvsKbvq8hspJ5CBJ3Wns1VXfLtmu6rbrWxMvKVSgR+XIeizuUeV8/6oXJ0X+kn8ufYJIcpKXq 3hZ4IClzsaF/9vSmse8/fZvGm4MzgPZMMUSxnvZ7tclZoTXccebyqkwXwaE2Oa+w==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1x5AIY-0000000CP3F-01zW; Sat, 12 Sep 2026 01:04:46 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH v2 3/6] tests: refactor event waiting Date: Sat, 12 Sep 2026 00:59:51 +0200 Message-ID: <20260912010440.52585046a56a.If26216381f176b27aa72be7380c57b6abf1c8663@changeid> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911230440.2087889-8-johannes@sipsolutions.net> References: <20260911230440.2087889-8-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_160448_920295_38CC6040 X-CRM114-Status: GOOD ( 12.35 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg Quite a bit of code is duplicated here, refactor it. One additional motivation is allowing async tests in the future, which this will simplify. Signed-off-by: Johannes Berg --- tests/hwsim/hostapd.py | 37 +++++ tests/hwsim/run-tests.py | 2 ++ tests/hwsim/wpasupplicant.py | 26 ++++------ [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg Quite a bit of code is duplicated here, refactor it. One additional motivation is allowing async tests in the future, which this will simplify. Signed-off-by: Johannes Berg --- tests/hwsim/hostapd.py | 37 +++++------------------------------- tests/hwsim/run-tests.py | 2 ++ tests/hwsim/wpasupplicant.py | 26 ++++--------------------- wpaspy/wpaspy.py | 21 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 54 deletions(-) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 9cfe5a2b61d0..a0a2340fdf36 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -81,21 +81,8 @@ class HostapdGlobal: return self.ctrl.request(cmd, timeout) def wait_event(self, events, timeout): - start = os.times()[4] - while True: - while self.mon.pending(): - ev = self.mon.recv() - logger.debug(self.dbg + "(global): " + ev) - for event in events: - if event in ev: - return ev - now = os.times()[4] - remaining = start + timeout - now - if remaining <= 0: - break - if not self.mon.pending(timeout=remaining): - break - return None + return wpaspy.wait_event(self.mon, events, timeout, + log_prefix=self.dbg + "(global): ") def add(self, ifname, driver=None): cmd = "ADD " + ifname + " " + hapd_ctrl @@ -303,23 +290,9 @@ class Hostapd: logger.debug(self.dbg + ": " + ev) def wait_event(self, events, timeout): - if not isinstance(events, list): - raise Exception("Hostapd.wait_event() called with incorrect events argument type") - start = os.times()[4] - while True: - while self.mon.pending(): - ev = self.mon.recv() - logger.debug(self.dbg + ": " + ev) - for event in events: - if event in ev: - return ev - now = os.times()[4] - remaining = start + timeout - now - if remaining <= 0: - break - if not self.mon.pending(timeout=remaining): - break - return None + return wpaspy.wait_event(self.mon, events, timeout, + log_prefix=self.dbg + ": ") + def wait_sta(self, addr=None, timeout=2, wait_4way_hs=False): ev = self.wait_event(["AP-STA-CONNECT"], timeout=timeout) diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index 52d64828c342..f113b8149347 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -12,6 +12,8 @@ import gc import sys import time import glob +import asyncio +import inspect from datetime import datetime import argparse import subprocess diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index b5e241a825ba..15178e2b817e 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -880,33 +880,15 @@ class WpaSupplicant: return self.group_form_result(ev, expect_failure, go_neg_res) raise Exception("P2P_CONNECT failed") - def _wait_event(self, mon, pfx, events, timeout): - if not isinstance(events, list): - raise Exception("WpaSupplicant._wait_event() called with incorrect events argument type") - start = os.times()[4] - while True: - while mon.pending(): - ev = mon.recv() - logger.debug(self.dbg + pfx + ev) - for event in events: - if event in ev: - return ev - now = os.times()[4] - remaining = start + timeout - now - if remaining <= 0: - break - if not mon.pending(timeout=remaining): - break - return None - def wait_event(self, events, timeout=10): - return self._wait_event(self.mon, ": ", events, timeout) + return wpaspy.wait_event(self.mon, events, timeout, + log_prefix=self.dbg + ": ") def wait_global_event(self, events, timeout): if self.global_iface is None: return self.wait_event(events, timeout) - return self._wait_event(self.global_mon, "(global): ", - events, timeout) + return wpaspy.wait_event(self.global_mon, events, timeout, + log_prefix=self.dbg + "(global): ") def wait_group_event(self, events, timeout=10): if not isinstance(events, list): diff --git a/wpaspy/wpaspy.py b/wpaspy/wpaspy.py index 5b8140b7c99f..eb7f06ded838 100644 --- a/wpaspy/wpaspy.py +++ b/wpaspy/wpaspy.py @@ -10,6 +10,9 @@ import os import stat import socket import select +import logging + +logger = logging.getLogger() counter = 0 @@ -147,3 +150,21 @@ class Ctrl: except UnicodeDecodeError as e: r = res return r + +def wait_event(sock, events, timeout=10, log_prefix=""): + assert isinstance(events, list), "'events' must be a list" + start = os.times()[4] + while True: + while sock.pending(): + ev = sock.recv() + logger.debug(log_prefix + ev) + for event in events: + if event in ev: + return ev + now = os.times()[4] + remaining = start + timeout - now + if remaining <= 0: + break + if not sock.pending(timeout=remaining): + break + return None From patchwork Fri Sep 11 12:59:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 2303247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=nHk4yX+l; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=ISOCQAPS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hhVbB4j0Cz1y1f for ; Sat, 12 Sep 2026 09:08:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gJkb+KLXRxky6tpjwuaz58N6ZsZhzgcGWHUz71RAYs4=; b=nHk4yX+lBFldjF I3b+RvunXV8Fdr/PrbR8EsE7itaRmzoCl6bkGr5ZmW7b2Oh8t+daOdcXTfP7D4xLbdkh3OFB0IItq 773xp45wtpnUbhTH7IR7CQC4AK89pKffjda+QF+zB7pH0wEEo3BypUYSYbh3kfbpOdrIqkciinvPT txkTBvVKdBYXxj+ZOAxJc8azUunMXLGj8Pgpd1Cp2O7SaTFpXZai5sORlh7MbnZOhbqMclzNh1fAX yARMKSgfHf7wu8LEEuibFtG4YXdbTnRNEMLjD5w5LucyUj+n1p+rX3HNJxyLqyPhqrverwPqkhbiJ V2qLe8mARj2IAlCkZymg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIe-00000000KV2-3L9O; Fri, 11 Sep 2026 23:04:52 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIb-00000000KSi-3LHS for hostap@lists.infradead.org; Fri, 11 Sep 2026 23:04:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=4LlXpjQVfUvXMecUdqaISg/pgqkES5CsDX4hM3AwUxo=; t=1789167889; x=1790377489; b=ISOCQAPStGZO5UA8/LuU5v157M/PAgM+HdsiqXcJLc9MQfi 3an51lObGKerg+Y1UVPniJg0kr78Xaq+nqyOesKnz767Jvhnwxnix7mCpTP6OhXC0CDSEgLH1qI5i oXc+xYbHxJcmbwMQT2/oOPseQnWUZupiCPvTiG4/cKhYm0E9W8Dxd8ArtWAfDo08RGWybzm/wuyAL AbwsRG5jM0jB1tUEqFQfWC+xatyp6pn9eRv9LKB2irPcRTYk9bhZNb0woBNXQsIC/nfqDacjyVzDJ RZGJLWDTpeFGRf8oG3bilhXxpTUQdvB17DznHfcVO9JWJIpG096mojsX+3TIRN5Q==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1x5AIY-0000000CP3F-2O35; Sat, 12 Sep 2026 01:04:46 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH v2 4/6] tests: refactor Hostapd event checks Date: Sat, 12 Sep 2026 00:59:52 +0200 Message-ID: <20260912010440.8cf6eb51d57a.Ia1ffc70a0b109cc59c2439a3335b528ef647b904@changeid> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911230440.2087889-8-johannes@sipsolutions.net> References: <20260911230440.2087889-8-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_160449_858094_99CAEB6D X-CRM114-Status: GOOD ( 10.46 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg Quite a bit of code is duplicated here, refactor it. Again, part of the motiviation is async code later. Signed-off-by: Johannes Berg --- tests/hwsim/hostapd.py | 43 ++++++++++++++++++++ 1 file changed, 20 insertions(+), 23 deletions(-) Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg Quite a bit of code is duplicated here, refactor it. Again, part of the motiviation is async code later. Signed-off-by: Johannes Berg --- tests/hwsim/hostapd.py | 43 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index a0a2340fdf36..6ce6701667b9 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -293,37 +293,34 @@ class Hostapd: return wpaspy.wait_event(self.mon, events, timeout, log_prefix=self.dbg + ": ") + @staticmethod + def _check_sta_event(ev, addr, what): + if ev is None: + raise Exception("AP did not report " + what) + if addr and addr not in ev: + raise Exception("Unexpected STA address in " + what + + " event: " + ev) + return ev def wait_sta(self, addr=None, timeout=2, wait_4way_hs=False): - ev = self.wait_event(["AP-STA-CONNECT"], timeout=timeout) - if ev is None: - raise Exception("AP did not report STA connection") - if addr and addr not in ev: - raise Exception("Unexpected STA address in connection event: " + ev) + ev = self._check_sta_event( + self.wait_event(["AP-STA-CONNECT"], timeout=timeout), addr, + "STA connection") if wait_4way_hs: - ev2 = self.wait_event(["EAPOL-4WAY-HS-COMPLETED"], - timeout=timeout) - if ev2 is None: - raise Exception("AP did not report 4-way handshake completion") - if addr and addr not in ev2: - raise Exception("Unexpected STA address in 4-way handshake completion event: " + ev2) + self._check_sta_event( + self.wait_event(["EAPOL-4WAY-HS-COMPLETED"], timeout=timeout), + addr, "4-way handshake completion") return ev def wait_sta_disconnect(self, addr=None, timeout=2): - ev = self.wait_event(["AP-STA-DISCONNECT"], timeout=timeout) - if ev is None: - raise Exception("AP did not report STA disconnection") - if addr and addr not in ev: - raise Exception("Unexpected STA address in disconnection event: " + ev) - return ev + return self._check_sta_event( + self.wait_event(["AP-STA-DISCONNECT"], timeout=timeout), addr, + "STA disconnection") def wait_4way_hs(self, addr=None, timeout=1): - ev = self.wait_event(["EAPOL-4WAY-HS-COMPLETED"], timeout=timeout) - if ev is None: - raise Exception("hostapd did not report 4-way handshake completion") - if addr and addr not in ev: - raise Exception("Unexpected STA address in 4-way handshake completion event: " + ev) - return ev + return self._check_sta_event( + self.wait_event(["EAPOL-4WAY-HS-COMPLETED"], timeout=timeout), + addr, "4-way handshake completion") def wait_ptkinitdone(self, addr, timeout=2): while timeout > 0: From patchwork Fri Sep 11 12:59:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 2303252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=NNBv9fys; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=vbRbZyKF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hhVbT0vlfz1xwp for ; Sat, 12 Sep 2026 09:08:53 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+g+s/VITvxpNagcAGRe433Imo32NaqhC7z57gQFHLNc=; b=NNBv9fys+QntKE WEIQYBQDJe9VSnUlcAFhIQd7F0JpcA3uQ2+4fOkLAlJccuEY9gVTwIiPiONNd2zyOLYksdWUmW4yp cVJZFrwlwIgETJut3/LjmhzvCrPvmc9fjtMXf9XzCcoI1BUa2eLEvb17g9ulx7wI4od8XpdfwK3lK gepu9xsDtaeUG22kj7BxLA3zhz9WMbK/pwP9QCPQ/sPw455iJKPIqilkWrwkuKMJco01Clv2cfhEV luuQp1Ju3eiP/x/a0R8fwH7shx40eAIKv32F4TtB+hH7d1OumAO9AxD00v7AaQTnwti0cWbuLvgkM qwC3GtfxkRU3Unbsvzsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIf-00000000KVH-0KVR; Fri, 11 Sep 2026 23:04:53 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIb-00000000KSq-49aj for hostap@lists.infradead.org; Fri, 11 Sep 2026 23:04:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=PGl1Y9+ZVd9F4FQ7XOR+LC//qetecg8QJWHKi1QTPUg=; t=1789167889; x=1790377489; b=vbRbZyKFb8xN4avfhddn2MdpgkwGuox4+NhwmbTTsavxmT/ H1VhQ8/vZJ2bcGwsdSK/EbQngFedU1KovZTE3kFfDAfHE96h80/jeIF3aWXu392Av08CspoodibuG wRQvUrig2U2nSSJ/79LNKuAQy6gy4OIrneUF0ccvl5aK8Z8jIC7ZtNKiifm6Uty++qeeP/moHlXHO C/IyDg9CZjsWIJVxU3N8Jq3Y948L3L8VAJTkrkTmxGkraM8OBh2WjFMjNCUcqeM2xdLPwQtmetpF+ zGgiJcdCaY5Uv8v0LM61CPNHm7+/n7LfrMhUDFEmE68ibzOw2Akx7lHwF5/t6OHA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1x5AIZ-0000000CP3F-0jCd; Sat, 12 Sep 2026 01:04:47 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH v2 5/6] tests: hwsim: add async infrastructure Date: Sat, 12 Sep 2026 00:59:53 +0200 Message-ID: <20260912010440.a60d49a635e6.I7726b656889d36b4a0d9cc969ad41b2bc507f76e@changeid> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911230440.2087889-8-johannes@sipsolutions.net> References: <20260911230440.2087889-8-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_160450_339575_D9FFD303 X-CRM114-Status: GOOD ( 12.70 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg Add infrastructure to be able to write async tests. Current tests are fine with sync code, however, the new relay infrastructure is much better as async. Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg Add infrastructure to be able to write async tests. Current tests are fine with sync code, however, the new relay infrastructure is much better as async. Add the basic infrastructure (including the hwsim connectivity check, which takes a bit of effort) that allows for writing async tests. Signed-off-by: Johannes Berg --- tests/hwsim/hostapd.py | 31 +++++++++ tests/hwsim/hwsim_utils.py | 118 +++++++++++++++++++++++++++-------- tests/hwsim/run-tests.py | 11 +++- tests/hwsim/wpasupplicant.py | 29 +++++++++ wpaspy/wpaspy.py | 39 ++++++++++++ 5 files changed, 199 insertions(+), 29 deletions(-) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 6ce6701667b9..e855390c7fd6 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -219,6 +219,10 @@ class Hostapd: logger.debug(self.dbg + ": CTRL: " + cmd) return self.ctrl.request(cmd) + async def request_async(self, cmd): + logger.debug(self.dbg + ": CTRL: " + cmd) + return await self.ctrl.request_async(cmd) + def ping(self): return "PONG" in self.request("PING") @@ -293,6 +297,10 @@ class Hostapd: return wpaspy.wait_event(self.mon, events, timeout, log_prefix=self.dbg + ": ") + async def wait_event_async(self, events, timeout): + return await wpaspy.wait_event_async(self.mon, events, timeout, + log_prefix=self.dbg + ": ") + @staticmethod def _check_sta_event(ev, addr, what): if ev is None: @@ -312,6 +320,17 @@ class Hostapd: addr, "4-way handshake completion") return ev + async def wait_sta_async(self, addr=None, timeout=2, wait_4way_hs=False): + ev = self._check_sta_event( + await self.wait_event_async(["AP-STA-CONNECT"], timeout=timeout), + addr, "STA connection") + if wait_4way_hs: + self._check_sta_event( + await self.wait_event_async(["EAPOL-4WAY-HS-COMPLETED"], + timeout=timeout), + addr, "4-way handshake completion") + return ev + def wait_sta_disconnect(self, addr=None, timeout=2): return self._check_sta_event( self.wait_event(["AP-STA-DISCONNECT"], timeout=timeout), addr, @@ -689,6 +708,18 @@ def add_ap(apdev, params, wait_enabled=True, no_enable=False, timeout=30, raise Exception("AP startup failed") return hapd +async def add_ap_async(apdev, params, wait_enabled=True, timeout=30, **kwargs): + hapd = add_ap(apdev, params, wait_enabled=False, **kwargs) + if kwargs.get('no_enable') or not wait_enabled: + return hapd + ev = await hapd.wait_event_async(["AP-ENABLED", "AP-DISABLED"], + timeout=timeout) + if ev is None: + raise Exception("AP startup timed out") + if "AP-ENABLED" not in ev: + raise Exception("AP startup failed") + return hapd + def add_bss(apdev, ifname, confname, ignore_error=False): phy = utils.get_phy(apdev) try: diff --git a/tests/hwsim/hwsim_utils.py b/tests/hwsim/hwsim_utils.py index c8d918cb7376..ad6ed37656ce 100644 --- a/tests/hwsim/hwsim_utils.py +++ b/tests/hwsim/hwsim_utils.py @@ -6,9 +6,11 @@ import os import time +import asyncio import logging logger = logging.getLogger() +import wpaspy from wpasupplicant import WpaSupplicant def sync_carrier(dev, ifname=None): @@ -54,13 +56,29 @@ def config_data_test(dev1, dev2, dev1group, dev2group, ifname1, ifname2): sync_carrier(dev2, ifname2) -def run_multicast_connectivity_test(dev1, dev2, tos=None, - dev1group=False, dev2group=False, - ifname1=None, ifname2=None, - config=True, timeout=5, - send_len=None, multicast_to_unicast=False, - broadcast_retry_c=1, - check_dup=False): +def _drive_sync(gen): + try: + req = next(gen) + while True: + req = gen.send(wpaspy.wait_event(*req)) + except StopIteration as e: + return e.value + +async def _drive_async(gen): + try: + req = next(gen) + while True: + req = gen.send(await wpaspy.wait_event_async(*req)) + except StopIteration as e: + return e.value + +def _run_multicast_connectivity_test(dev1, dev2, tos=None, + dev1group=False, dev2group=False, + ifname1=None, ifname2=None, + config=True, timeout=5, + send_len=None, multicast_to_unicast=False, + broadcast_retry_c=1, + check_dup=False): addr1 = dev1.get_addr(dev1group) addr2 = dev2.get_addr(dev2group) @@ -85,7 +103,7 @@ def run_multicast_connectivity_test(dev1, dev2, tos=None, ev = dev2.wait_group_event(["DATA-TEST-RX"], timeout=timeout) else: - ev = dev2.wait_event(["DATA-TEST-RX"], timeout=timeout) + ev = yield (dev2.mon, ["DATA-TEST-RX"], timeout, dev2.dbg + ": ") if ev is None: raise Exception("dev1->dev2 broadcast data delivery failed") if multicast_to_unicast: @@ -122,7 +140,7 @@ def run_multicast_connectivity_test(dev1, dev2, tos=None, ev = dev2.wait_group_event(["DATA-TEST-RX"], timeout=timeout) else: - ev = dev2.wait_event(["DATA-TEST-RX"], timeout=timeout) + ev = yield (dev2.mon, ["DATA-TEST-RX"], timeout, dev2.dbg + ": ") if not ev: return if not " id=" in ev: @@ -134,10 +152,14 @@ def run_multicast_connectivity_test(dev1, dev2, tos=None, if _id in rxed: raise Exception("duplicate packet with ID %d received" % _id) -def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, - ifname1=None, ifname2=None, config=True, timeout=5, - multicast_to_unicast=False, broadcast=True, - send_len=None, check_bcast_dup=False): +# see _run_multicast_connectivity_test() for arguments +def run_multicast_connectivity_test(*args, **kwargs): + return _drive_sync(_run_multicast_connectivity_test(*args, **kwargs)) + +def _run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, + ifname1=None, ifname2=None, config=True, timeout=5, + multicast_to_unicast=False, broadcast=True, + send_len=None, check_bcast_dup=False): addr1 = dev1.get_addr(dev1group) addr2 = dev2.get_addr(dev2group) @@ -165,7 +187,7 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, if dev2group: ev = dev2.wait_group_event(["DATA-TEST-RX"], timeout=timeout) else: - ev = dev2.wait_event(["DATA-TEST-RX"], timeout=timeout) + ev = yield (dev2.mon, ["DATA-TEST-RX"], timeout, dev2.dbg + ": ") if ev is None: raise Exception("dev1->dev2 unicast data delivery failed") if "DATA-TEST-RX {} {}".format(addr2, addr1) not in ev: @@ -178,11 +200,13 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, raise Exception("Unexpected dev1->dev2 unicast data length") if broadcast: - run_multicast_connectivity_test(dev1, dev2, tos, - dev1group, dev2group, - ifname1, ifname2, False, timeout, - send_len, False, broadcast_retry_c, - check_dup=check_bcast_dup) + yield from _run_multicast_connectivity_test(dev1, dev2, tos, + dev1group, dev2group, + ifname1, ifname2, + False, timeout, + send_len, False, + broadcast_retry_c, + check_dup=check_bcast_dup) cmd = "DATA_TEST_TX {} {} {}".format(addr1, addr2, tos) if send_len is not None: @@ -194,7 +218,7 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, if dev1group: ev = dev1.wait_group_event(["DATA-TEST-RX"], timeout=timeout) else: - ev = dev1.wait_event(["DATA-TEST-RX"], timeout=timeout) + ev = yield (dev1.mon, ["DATA-TEST-RX"], timeout, dev1.dbg + ": ") if ev is None: raise Exception("dev2->dev1 unicast data delivery failed") if "DATA-TEST-RX {} {}".format(addr1, addr2) not in ev: @@ -207,12 +231,14 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, raise Exception("Unexpected dev2->dev1 unicast data length") if broadcast: - run_multicast_connectivity_test(dev2, dev1, tos, - dev2group, dev1group, - ifname2, ifname1, False, timeout, - send_len, multicast_to_unicast, - broadcast_retry_c, - check_dup=check_bcast_dup) + yield from _run_multicast_connectivity_test(dev2, dev1, tos, + dev2group, dev1group, + ifname2, ifname1, + False, timeout, + send_len, + multicast_to_unicast, + broadcast_retry_c, + check_dup=check_bcast_dup) finally: if config: @@ -225,6 +251,10 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False, else: dev2.request("DATA_TEST_CONFIG 0") +# see _run_connectivity_test() for arguments +def run_connectivity_test(*args, **kwargs): + return _drive_sync(_run_connectivity_test(*args, **kwargs)) + def test_connectivity(dev1, dev2, dscp=None, tos=None, max_tries=1, dev1group=False, dev2group=False, ifname1=None, ifname2=None, config=True, timeout=5, @@ -261,6 +291,42 @@ def test_connectivity_iface(dev1, dev2, ifname, dscp=None, tos=None, test_connectivity(dev1, dev2, dscp, tos, ifname2=ifname, max_tries=max_tries, timeout=timeout) +async def test_connectivity_async(dev1, dev2, dscp=None, tos=None, max_tries=1, + dev1group=False, dev2group=False, + ifname1=None, ifname2=None, config=True, + timeout=5, multicast_to_unicast=False, + success_expected=True, broadcast=True, + send_len=None, check_bcast_dup=False): + if dscp: + tos = dscp << 2 + if not tos: + tos = 0 + + success = False + last_err = None + for i in range(0, max_tries): + try: + await _drive_async(_run_connectivity_test(dev1, dev2, tos, + dev1group, dev2group, + ifname1, ifname2, + config=config, + timeout=timeout, + multicast_to_unicast=multicast_to_unicast, + broadcast=broadcast, + send_len=send_len, + check_bcast_dup=check_bcast_dup)) + success = True + break + except Exception as e: + last_err = e + if i + 1 < max_tries: + await asyncio.sleep(1) + if success_expected and not success: + raise Exception(last_err) + if not success_expected and success: + raise Exception("Unexpected connectivity detected") + + def test_connectivity_p2p(dev1, dev2, dscp=None, tos=None): test_connectivity(dev1, dev2, dscp, tos, dev1group=True, dev2group=True) diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index f113b8149347..f35400368813 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -37,6 +37,11 @@ from check_kernel import check_kernel from wlantest import Wlantest from utils import HwsimSkip +def run_test_func(t, *args): + if inspect.iscoroutinefunction(t): + return asyncio.run(t(*args)) + return t(*args) + def set_term_echo(fd, enabled): [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] = termios.tcgetattr(fd) if enabled: @@ -632,11 +637,11 @@ def main(): params['logdir'] = args.logdir params['name'] = name params['prefix'] = os.path.join(args.logdir, name) - t(dev, apdev, params) + run_test_func(t, dev, apdev, params) elif t.__code__.co_argcount > 1: - t(dev, apdev) + run_test_func(t, dev, apdev) else: - t(dev) + run_test_func(t, dev) result = "PASS" if check_country_00: for d in dev: diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 15178e2b817e..db8eb297111a 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -270,6 +270,10 @@ class WpaSupplicant: logger.debug(self.dbg + ": CTRL: " + cmd) return self.ctrl.request(cmd, timeout=timeout) + async def request_async(self, cmd, timeout=10): + logger.debug(self.dbg + ": CTRL: " + cmd) + return await self.ctrl.request_async(cmd, timeout=timeout) + def global_request(self, cmd): if self.global_iface is None: return self.request(cmd) @@ -884,6 +888,10 @@ class WpaSupplicant: return wpaspy.wait_event(self.mon, events, timeout, log_prefix=self.dbg + ": ") + async def wait_event_async(self, events, timeout=10): + return await wpaspy.wait_event_async(self.mon, events, timeout, + log_prefix=self.dbg + ": ") + def wait_global_event(self, events, timeout): if self.global_iface is None: return self.wait_event(events, timeout) @@ -1174,6 +1182,27 @@ class WpaSupplicant: self.select_network(id) return id + async def connect_async(self, ssid=None, ssid2=None, timeout=None, + wait_connect=True, only_add_network=False, + **kwargs): + """ + Async equivalent of connect(): everything connect() does is quick + request/response setup except the final wait for + CTRL-EVENT-CONNECTED, so that part is done here as a real + (non-thread) asyncio wait instead. + """ + if timeout is None: + timeout = 20 if "eap" in kwargs else 15 + id = self.connect(ssid, ssid2, timeout=timeout, wait_connect=False, + only_add_network=only_add_network, **kwargs) + if only_add_network or not wait_connect: + return id + ev = await self.wait_event_async(["CTRL-EVENT-CONNECTED"], + timeout=timeout) + if ev is None: + raise Exception("Connection timed out") + return id + def scan(self, type=None, freq=None, no_wait=False, only_new=False, passive=False, timeout=15): if not no_wait: diff --git a/wpaspy/wpaspy.py b/wpaspy/wpaspy.py index eb7f06ded838..9b50b9b3050e 100644 --- a/wpaspy/wpaspy.py +++ b/wpaspy/wpaspy.py @@ -10,6 +10,7 @@ import os import stat import socket import select +import asyncio import logging logger = logging.getLogger() @@ -64,6 +65,8 @@ class Ctrl: if self.s != None: self.s.close() raise + # needed for async and non-async always uses select() + self.s.setblocking(False) self.started = True def __del__(self): @@ -151,6 +154,25 @@ class Ctrl: r = res return r + async def recv_async(self): + data = await asyncio.get_running_loop().sock_recv(self.s, 4096) + return data.decode() + + async def request_async(self, cmd, timeout=10): + if type(cmd) == str: + try: + cmd = cmd.encode() + except UnicodeDecodeError as e: + pass + if self.udp: + self.s.sendto(self.cookie + cmd, self.sockaddr) + else: + self.s.send(cmd) + try: + return await asyncio.wait_for(self.recv_async(), timeout) + except asyncio.TimeoutError: + raise Exception("Timeout on waiting response") + def wait_event(sock, events, timeout=10, log_prefix=""): assert isinstance(events, list), "'events' must be a list" start = os.times()[4] @@ -168,3 +190,20 @@ def wait_event(sock, events, timeout=10, log_prefix=""): if not sock.pending(timeout=remaining): break return None + +async def wait_event_async(sock, events, timeout=10, log_prefix=""): + assert isinstance(events, list), "'events' must be a list" + loop = asyncio.get_running_loop() + deadline = loop.time() + timeout + while True: + remaining = deadline - loop.time() + if remaining <= 0: + return None + try: + ev = await asyncio.wait_for(sock.recv_async(), remaining) + except asyncio.TimeoutError: + return None + logger.debug(log_prefix + ev) + for event in events: + if event in ev: + return ev From patchwork Fri Sep 11 12:59:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 2303246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=IC7UkEd9; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=u7Asd9AJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hhVb963nVz1xwp for ; Sat, 12 Sep 2026 09:08:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ceScOU54UQYu1i6fESAFjAwinvan/0RNCeSX7AfLPQc=; b=IC7UkEd9sNWdt2 fT4/n+w2Dxm4PZ37gPTOyt6wJXgnuIWj4Nnj+WNrckevNfls+wG791B1id+IjiHUGcbNI2JDZabHF AyDIeMAr6TQBtUResEd5JNF9cArGEdfj4HLxfJuzjgdemCI/0YaK3URVemHQ+KPuFVZkT90qlfaEh Ku8ChtQZG0x7FG5oXFNFKwysdDm+o331Nzo7Prlh+exiFv03w2zeafFkSN6ainLwz6H3Nusv9wlYt 9hTdt759z1ZFv5Cs4lgHbPklN3Rmd6rWpLCKPtOsKtSqCMAxnqErQnjviXudZzUOE/8YAgz5a5y0Y cklUrx5/yfHdcjxX1lPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIf-00000000KVW-12DE; Fri, 11 Sep 2026 23:04:53 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5AIc-00000000KT5-0wC7 for hostap@lists.infradead.org; Fri, 11 Sep 2026 23:04:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=/g455xmlwGhBaMuOgWO6AJouaEjXlo2Mm8tXfiU4APw=; t=1789167890; x=1790377490; b=u7Asd9AJ6ptkAZkHJuFaeNFbK19iDY8bwNDu3Vehwr67B7G 2UuzZz0420QCURFhcSkbNney4bSNdQknB3rWkuAnxhRTnhm70+nilOm7NxYOoudBkZPJFTDnmsKDa euFmqeKTPUssoM7ZXqvCbiT0LU2x3gOZF+g41R0HH1wk73Z2Dh51857UKVBk5EoyM0Axeu0XRECIU PFEtzzUx/puqwk0yGGFnL71gqkHsqxHNGFXvOz6Y27Rmyyu6O6jQ+iC3NGnAakrk18+dMnOlkUYDL 7D4Cwl9DjTbmUbQVdp+ihCUtezR4jCWOJ1ZkEBzapxhLU8e9R4ef1wLOsjfehOQA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__ECDSA_SECP256R1_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1x5AIZ-0000000CP3F-3mPL; Sat, 12 Sep 2026 01:04:48 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH v2 6/6] tests: hwsim: add hwsim relay code Date: Sat, 12 Sep 2026 00:59:54 +0200 Message-ID: <20260912010440.25fcdf64c6dc.I4a5b2e8479865b86b1c66fdc92288f92570a68f1@changeid> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911230440.2087889-8-johannes@sipsolutions.net> References: <20260911230440.2087889-8-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_160450_576458_8A108252 X-CRM114-Status: GOOD ( 24.92 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg For a lot of tests that we don't have now, it'd be useful to be able to modify or drop arbitrary frames going across the medium, such as beacons to test various CSA/critical update scenarios, missed b [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg For a lot of tests that we don't have now, it'd be useful to be able to modify or drop arbitrary frames going across the medium, such as beacons to test various CSA/critical update scenarios, missed beacons overlapping with CSA to force mac80211 to detect it from another link, etc. Even where it's not error conditions hostapd doesn't necessarily support all features we want to test. Add a hwsim relay module that registers with the wmediumd APIs and can be used by tests to intercept frames. By default it'll relay all frames unmodified, but frame handling layers can be stacked on top of it as in the example test. Right now the code has one to wait for frames (relay.WaitFrame), recalculate BIP for protected group management frames and beacons after they've been modified by further layers (bip.GroupMgmtSigner) and one to decrypt management frames before passing to the next layer and re-encrypt them if they were changed (ccmp.ProtectedMgmtCrypto). The choice for CCMP is because that's simpler with python. All of this will likely only work right with UML's time-travel, but that's not really that much of an issue, and it allows us to write a large number of tests that'd otherwise be impossible. Signed-off-by: Johannes Berg --- v2: async --- tests/hwsim/hostapd.py | 7 + tests/hwsim/relay/__init__.py | 305 ++++++++++++++++++++++++++++++++ tests/hwsim/relay/bip.py | 86 +++++++++ tests/hwsim/relay/ccmp.py | 97 ++++++++++ tests/hwsim/relay/frame.py | 119 +++++++++++++ tests/hwsim/test_hwsim_relay.py | 146 +++++++++++++++ 6 files changed, 760 insertions(+) create mode 100644 tests/hwsim/relay/__init__.py create mode 100644 tests/hwsim/relay/bip.py create mode 100644 tests/hwsim/relay/ccmp.py create mode 100644 tests/hwsim/relay/frame.py create mode 100644 tests/hwsim/test_hwsim_relay.py diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index e855390c7fd6..00b18f9357b4 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -432,6 +432,13 @@ class Hostapd: res = self.request(cmd + addr + " " + info) else: res = self.request(cmd + addr) + return self._parse_sta_mib(res) + + def get_link_sta(self, addr): + return self._parse_sta_mib(self.request("LINK_STA " + addr)) + + @staticmethod + def _parse_sta_mib(res): lines = res.splitlines() vals = dict() first = True diff --git a/tests/hwsim/relay/__init__.py b/tests/hwsim/relay/__init__.py new file mode 100644 index 000000000000..972d9a5c78c5 --- /dev/null +++ b/tests/hwsim/relay/__init__.py @@ -0,0 +1,305 @@ +# +# hwsim relay - interceptor for hwsim using wmediumd API +# +# Copyright (C) 2026 Intel Corporation +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. +# +# +# This code allows intercepting and manipulating/dropping frames that +# are being transmitted over the hwsim medium simulation, for testing +# purposes. +# +# Note that it will only really work in UML's time-travel. +# + +import asyncio +import os +import errno +import logging + +import netlink + +logger = logging.getLogger() + +HWSIM_CMD_REGISTER = 1 +HWSIM_CMD_FRAME = 2 +HWSIM_CMD_TX_INFO_FRAME = 3 + +HWSIM_ATTR_ADDR_RECEIVER = 1 +HWSIM_ATTR_ADDR_TRANSMITTER = 2 +HWSIM_ATTR_FRAME = 3 +HWSIM_ATTR_FLAGS = 4 +HWSIM_ATTR_RX_RATE = 5 +HWSIM_ATTR_SIGNAL = 6 +HWSIM_ATTR_TX_INFO = 7 +HWSIM_ATTR_COOKIE = 8 +HWSIM_ATTR_FREQ = 19 +HWSIM_ATTR_NO_MONITOR = 32 + +HWSIM_TX_CTL_REQ_TX_STATUS = 1 << 0 +HWSIM_TX_CTL_NO_ACK = 1 << 1 +HWSIM_TX_STAT_ACK = 1 << 2 + +IEEE80211_TX_MAX_RATES = 4 + + +def _tx_info_all_invalid(): + # struct hwsim_tx_rate { idx = -1, count = 0 } + return b'\xff\x00' * IEEE80211_TX_MAX_RATES + + +def radio_addr_for_iface(ifname): + phy = os.path.basename(os.readlink( + '/sys/class/net/%s/phy80211' % ifname)) + with open('/sys/class/ieee80211/%s/addresses' % phy) as f: + addrs = f.read().split() + return bytes.fromhex(addrs[1].replace(':', '')) + + +class RelayLayer: + """ + Base layer for frame interception - each layer has its own + .intercept() like the HwsimRelay() itself. + + Used as "async with XyzLayer(...) as layer:" just like + the relay itself. + """ + + def __init__(self, upstream): + self._upstream = upstream + self._downstream = self._default + + def __enter__(self): + self._prev = self._upstream.intercept + self._upstream.intercept = self._run + return self + + def __exit__(self, exc_type, exc_value, traceback): + self._upstream.intercept = self._prev + + @property + def intercept(self): + return self._downstream + + @intercept.setter + def intercept(self, fn): + self._downstream = fn + + def _default(self, src, freq, frame): + return frame + + def _run(self, src, freq, frame): + raise NotImplementedError + + +class WaitFrame(RelayLayer): + def __init__(self, upstream, matchers): + super().__init__(upstream) + self._matchers = list(matchers) + self._results = asyncio.Queue() + + def _run(self, src, freq, frame): + for matcher in self._matchers: + result = matcher.match(src, freq, frame) + if result is not None: + self._results.put_nowait(result) + break + return self.intercept(src, freq, frame) + + async def wait_for_frame(self, timeout=5): + try: + return await asyncio.wait_for(self._results.get(), timeout=timeout) + except asyncio.TimeoutError: + return None + + +_MGMT_SUBTYPES = { + 0: 'AssocReq', + 1: 'AssocResp', + 2: 'ReassocReq', + 3: 'ReassocResp', + 4: 'ProbeReq', + 5: 'ProbeResp', + 6: 'TimingAdv', + 8: 'Beacon', + 9: 'ATIM', + 10: 'Disassoc', + 11: 'Auth', + 12: 'Deauth', + 13: 'Action', + 14: 'ActionNoAck', +} + + +def _frame_type_str(frame): + if len(frame) < 2: + return '?' + + fc = frame[0] + ftype = (fc >> 2) & 0x3 + subtype = (fc >> 4) & 0xf + if ftype == 0: + return _MGMT_SUBTYPES.get(subtype, 'Mgmt(%d)' % subtype) + + return { + 1: 'Ctrl', + 2: 'Data', + 3: 'Ext' + }[ftype] + '(%d)' % subtype + + +class HwsimRelay: + def __init__(self, intercept=None, rx_rate=1, signal=-30, radios=None): + """ + By default every frame is passed through unmodified to every + radio other than the sender, but the intercept call can override + that. + + intercept(src_addr: bytes, freq: int|None, frame: bytes) -> frame: bytes | None + + The returned frame (or None to drop it) is sent to every radio + other than the sender - all receivers always see the same frame, + as they would over the air. + + Used as "async with HwsimRelay() as relay:". + """ + self._conn = netlink.Connection(netlink.NETLINK_GENERIC) + self._fid = netlink.genl_controller.get_family_id(b'MAC80211_HWSIM') + self._radios = set() + for addr in (radios or []): + self.add_radio(addr) + self._intercept_fn = intercept or self._default_intercept + self._rx_rate = rx_rate + self._signal = signal + self._running = False + self._exc = None + self._task = None + + @property + def intercept(self): + return self._intercept_fn + + @intercept.setter + def intercept(self, fn): + self._intercept_fn = fn or self._default_intercept + + def add_radio(self, addr): + if isinstance(addr, str): + addr = bytes.fromhex(addr.replace(':', '')) + self._radios.add(addr) + + def add_radio_for_iface(self, ifname): + self.add_radio(radio_addr_for_iface(ifname)) + + def _default_intercept(self, src, freq, frame): + return frame + + def register(self): + msg = netlink.GenlMessage(self._fid, HWSIM_CMD_REGISTER, + flags=netlink.NLM_F_REQUEST | + netlink.NLM_F_ACK) + msg.send_and_recv(self._conn) + + async def __aenter__(self): + self.register() + self._running = True + self._task = asyncio.current_task() + asyncio.get_running_loop().add_reader(self._conn.descriptor.fileno(), + self._on_readable) + return self + + async def __aexit__(self, exc_type, exc_value, traceback): + asyncio.get_running_loop().remove_reader(self._conn.descriptor.fileno()) + self._running = False + self._conn.descriptor.close() + if self._exc is not None: + exc, self._exc = self._exc, None + # replaces the CancelledError we injected below to unblock + # whatever the body was awaiting when the reader died + raise exc + + def _recv_one(self): + msg = self._conn.recv() + if msg.type != self._fid or len(msg.payload) < 4: + return + cmd = msg.payload[0] + if cmd != HWSIM_CMD_FRAME: + logger.debug("hwsim_relay: non-FRAME cmd=%d" % (cmd,)) + return + attrs = netlink.parse_attributes(msg.payload[4:]) + self._handle_frame(attrs) + + def _on_readable(self): + try: + self._recv_one() + except OSError as e: + # hwsim rejects frames for radios not started with EINVAL + if e.errno != errno.EINVAL: + logger.warning("hwsim_relay: dropping failed op: %r" % (e,)) + except Exception as e: + self._exc = e + # wake up whatever the body is currently awaiting instead of + # waiting for it to time out or hang forever + if self._task is not None: + self._task.cancel() + + def _handle_frame(self, attrs): + if HWSIM_ATTR_ADDR_TRANSMITTER not in attrs or \ + HWSIM_ATTR_FRAME not in attrs or \ + HWSIM_ATTR_COOKIE not in attrs: + return + + src = attrs[HWSIM_ATTR_ADDR_TRANSMITTER].str() + frame = attrs[HWSIM_ATTR_FRAME].str() + freq = attrs[HWSIM_ATTR_FREQ].u32() if HWSIM_ATTR_FREQ in attrs else None + flags = attrs[HWSIM_ATTR_FLAGS].u32() if HWSIM_ATTR_FLAGS in attrs else 0 + cookie = attrs[HWSIM_ATTR_COOKIE].str() + + self._radios.add(src) + delivered = False + logger.debug("hwsim_relay: %s src=%s len=%d freq=%s flags=0x%x" % + (_frame_type_str(frame), src.hex(), len(frame), freq, flags)) + + try: + out_frame = self._intercept_fn(src, freq, frame) + + if out_frame is not None: + for dst in tuple(self._radios): + if dst != src: + self._deliver(src, dst, out_frame, freq, cookie) + delivered = True + finally: + self._ack(src, flags, cookie, delivered) + + def _deliver(self, src, dst, frame, freq, cookie): + attrs = [ + netlink.StrAttr(HWSIM_ATTR_ADDR_TRANSMITTER, src), + netlink.StrAttr(HWSIM_ATTR_ADDR_RECEIVER, dst), + netlink.StrAttr(HWSIM_ATTR_FRAME, frame), + netlink.U32Attr(HWSIM_ATTR_RX_RATE, self._rx_rate), + netlink.U32Attr(HWSIM_ATTR_SIGNAL, self._signal & 0xffffffff), + netlink.Attr(HWSIM_ATTR_COOKIE, cookie), + ] + if freq is not None: + attrs.append(netlink.U32Attr(HWSIM_ATTR_FREQ, freq)) + msg = netlink.GenlMessage(self._fid, HWSIM_CMD_FRAME, attrs=attrs, + flags=netlink.NLM_F_REQUEST) + msg.send(self._conn) + + def _ack(self, src, flags, cookie, delivered): + tx_flags = HWSIM_TX_STAT_ACK if delivered and \ + not (flags & HWSIM_TX_CTL_NO_ACK) else 0 + attrs = [ + netlink.StrAttr(HWSIM_ATTR_ADDR_TRANSMITTER, src), + netlink.U32Attr(HWSIM_ATTR_FLAGS, tx_flags), + netlink.Attr(HWSIM_ATTR_COOKIE, cookie), + netlink.U32Attr(HWSIM_ATTR_SIGNAL, self._signal & 0xffffffff), + netlink.StrAttr(HWSIM_ATTR_TX_INFO, _tx_info_all_invalid()), + ] + if not delivered: + attrs.append(netlink.FlagAttr(HWSIM_ATTR_NO_MONITOR)) + msg = netlink.GenlMessage(self._fid, HWSIM_CMD_TX_INFO_FRAME, + attrs=attrs, flags=netlink.NLM_F_REQUEST) + msg.send(self._conn) diff --git a/tests/hwsim/relay/bip.py b/tests/hwsim/relay/bip.py new file mode 100644 index 000000000000..0e1395c01506 --- /dev/null +++ b/tests/hwsim/relay/bip.py @@ -0,0 +1,86 @@ +# +# Copyright (C) 2026 Intel Corporation +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +try: + from Cryptodome.Cipher import AES + from Cryptodome.Hash import CMAC +except ImportError: + from Crypto.Cipher import AES + from Crypto.Hash import CMAC + +from . import RelayLayer +from .frame import MGMT_HDR_LEN, is_beacon, masked_fc_aad + +WLAN_EID_MMIE = 76 + + +def find_mmie(frame, mic_len=8): + mmie_len = 2 + 2 + 6 + mic_len + if len(frame) < MGMT_HDR_LEN + mmie_len: + return None + mmie = frame[-mmie_len:] + if mmie[0] != WLAN_EID_MMIE or mmie[1] != mmie_len - 2: + return None + return mmie + +def bip_aad(frame): + return masked_fc_aad(frame) + +def bip_cmac_mic(key, frame, mic_len=8): + aad = bip_aad(frame) + body = bytearray(frame[MGMT_HDR_LEN:]) + if is_beacon(frame): + body[0:8] = b'\x00' * 8 + body[-mic_len:] = b'\x00' * mic_len + + c = CMAC.new(key, ciphermod=AES) + c.update(aad + bytes(body)) + return c.digest()[:mic_len] + + +def resign_frame(frame, key): + mmie = find_mmie(frame) + if mmie is None: + return frame + mic_len = len(mmie) - (2 + 2 + 6) + mic = bip_cmac_mic(key, frame, mic_len) + return frame[:-mic_len] + mic + + +def group_key_getter(hapd): + def get_key(frame): + cmd = "GET_BIGTK" if is_beacon(frame) else "GET_IGTK" + res = hapd.request(cmd) + if res is None or "FAIL" in res: + return None + return bytes.fromhex(res.strip()) + return get_key + + +class GroupMgmtSigner(RelayLayer): + """ + Recalculate the MIC for a group-addressed frame after the inner + layers have changed it. + + get_key: callable get_key(frame) or hostapd instance + """ + + def __init__(self, upstream, get_key): + super().__init__(upstream) + self._get_key = get_key if callable(get_key) else \ + group_key_getter(get_key) + + def _run(self, src, freq, frame): + out_frame = self.intercept(src, freq, frame) + if out_frame is None or find_mmie(out_frame) is None: + return out_frame + return self._resign(frame, out_frame) + + def _resign(self, old, frame): + if frame == old: + return frame + key = self._get_key(frame) + return resign_frame(frame, key) if key is not None else frame diff --git a/tests/hwsim/relay/ccmp.py b/tests/hwsim/relay/ccmp.py new file mode 100644 index 000000000000..3f666178291d --- /dev/null +++ b/tests/hwsim/relay/ccmp.py @@ -0,0 +1,97 @@ +# +# Copyright (C) 2026 Intel Corporation +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. +# + +try: + from Cryptodome.Cipher import AES +except ImportError: + from Crypto.Cipher import AES + +from . import RelayLayer +from .frame import (IEEE80211_FCTL_PROTECTED, MGMT_HDR_LEN, is_protected_mgmt, + masked_fc_aad, client_addr) + +CCMP_HDR_LEN = 8 + + +def _mgmt_aad_nonce(frame): + aad = masked_fc_aad(frame, extra_mask=IEEE80211_FCTL_PROTECTED) + aad += bytes([frame[22] & 0x0f, 0]) + + ccmp_hdr = frame[MGMT_HDR_LEN:MGMT_HDR_LEN + CCMP_HDR_LEN] + pn = bytes([ccmp_hdr[7], ccmp_hdr[6], ccmp_hdr[5], ccmp_hdr[4], + ccmp_hdr[1], ccmp_hdr[0]]) + nonce = bytes([0x10]) + frame[10:16] + pn + return aad, nonce + + +def ccmp_decrypt_mgmt(frame, tk, mic_len=8): + aad, nonce = _mgmt_aad_nonce(frame) + + body_start = MGMT_HDR_LEN + CCMP_HDR_LEN + ciphertext = frame[body_start:len(frame) - mic_len] + mic = frame[len(frame) - mic_len:] + + cipher = AES.new(tk, AES.MODE_CCM, nonce=nonce, mac_len=mic_len) + cipher.update(aad) + return cipher.decrypt_and_verify(ciphertext, mic) + + +def ccmp_encrypt_mgmt(frame, tk, body, mic_len=8): + aad, nonce = _mgmt_aad_nonce(frame) + + cipher = AES.new(tk, AES.MODE_CCM, nonce=nonce, mac_len=mic_len) + cipher.update(aad) + ciphertext, mic = cipher.encrypt_and_digest(body) + + body_start = MGMT_HDR_LEN + CCMP_HDR_LEN + return frame[:body_start] + ciphertext + mic + + +def sta_tk_getter(hapd, cipher="CCMP"): + def get_tk(addr): + addr_str = addr.hex(':') + + # might be a link address, try to resolve it + sta = hapd.get_link_sta(addr_str) + resolved = sta.get('addr') + if resolved and resolved != 'FAIL': + addr_str = resolved + + ptksa = hapd.get_ptksa(addr_str, cipher) + if ptksa is None: + return None + return bytes.fromhex(ptksa['tk']) + return get_tk + + +class ProtectedMgmtCrypto(RelayLayer): + """ + Decrypt CCMP-protected management frames and pass them to + the next layer unencrypted (but protected bit still set) + + get_tk: callable get_tk(client_addr) or hostapd instance + """ + def __init__(self, upstream, get_tk): + super().__init__(upstream) + self._get_tk = get_tk if callable(get_tk) else sta_tk_getter(get_tk) + + def _run(self, src, freq, frame): + if is_protected_mgmt(frame): + tk = self._get_tk(client_addr(frame)) + if tk is not None: + try: + body = ccmp_decrypt_mgmt(frame, tk) + except ValueError: + body = None + if body is not None: + clear_frame = frame[:MGMT_HDR_LEN] + body + out_frame = self.intercept(src, freq, clear_frame) + if out_frame is not None and is_protected_mgmt(out_frame): + return ccmp_encrypt_mgmt(frame, tk, + out_frame[MGMT_HDR_LEN:]) + return out_frame + return self.intercept(src, freq, frame) diff --git a/tests/hwsim/relay/frame.py b/tests/hwsim/relay/frame.py new file mode 100644 index 000000000000..36c406121f68 --- /dev/null +++ b/tests/hwsim/relay/frame.py @@ -0,0 +1,119 @@ +# +# 802.11 frame helpers for frame relay handling +# +# Copyright (C) 2026 Intel Corporation +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. +# + +import struct + +IEEE80211_FCTL_RETRY = 0x0800 +IEEE80211_FCTL_PM = 0x1000 +IEEE80211_FCTL_MOREDATA = 0x2000 +IEEE80211_FCTL_PROTECTED = 0x4000 +IEEE80211_FCTL_FTYPE = 0x000c +IEEE80211_FTYPE_MGMT = 0x0000 + +STYPE_ASSOC_REQ = 0 +STYPE_ASSOC_RESP = 1 +STYPE_REASSOC_RESP = 3 +STYPE_PROBE_RESP = 5 +STYPE_BEACON = 8 +STYPE_DEAUTH = 12 + +MGMT_HDR_LEN = 24 + +WLAN_EID_EXTENSION = 255 + + +def frame_fc(frame): + return struct.unpack_from('> 4) & 0xf + + +def is_mgmt_subtype(frame, stype): + return is_ftype_mgmt(frame) and mgmt_subtype(frame) == stype + + +def is_beacon(frame): + return is_mgmt_subtype(frame, STYPE_BEACON) + + +def is_protected_mgmt(frame): + if len(frame) < MGMT_HDR_LEN: + return False + return is_ftype_mgmt(frame) and bool(frame_fc(frame) & IEEE80211_FCTL_PROTECTED) + + +def is_protected_deauth(frame): + return is_protected_mgmt(frame) and is_mgmt_subtype(frame, STYPE_DEAUTH) + + +def ies_start_offset(frame): + """Byte offset of the IE section for beacon/probe-resp/assoc-resp.""" + stype = mgmt_subtype(frame) + if stype in (STYPE_BEACON, STYPE_PROBE_RESP): + return 24 + 12 # timestamp(8) + beacon_interval(2) + capab(2) + if stype in (STYPE_ASSOC_RESP, STYPE_REASSOC_RESP): + return 24 + 6 # capab(2) + status(2) + aid(2) + raise ValueError("unsupported mgmt subtype %d for IE parsing" % stype) + + +def iter_elements(buf, start=0): + """Yield (eid, ext_id_or_None, elem_start, payload_off, payload_len).""" + i = start + while i + 2 <= len(buf): + eid = buf[i] + elen = buf[i + 1] + if i + 2 + elen > len(buf): + break + payload_off = i + 2 + payload_len = elen + ext_id = None + if eid == WLAN_EID_EXTENSION and elen >= 1: + ext_id = buf[payload_off] + payload_off += 1 + payload_len -= 1 + yield eid, ext_id, i, payload_off, payload_len + i += 2 + elen + + +def find_element(buf, start, eid, ext_id=None): + for e, x, elem_start, payload_off, payload_len in iter_elements(buf, start): + if e == eid and x == ext_id: + elem_total_len = (payload_off + payload_len) - elem_start + return elem_start, elem_total_len, payload_off, payload_len + return None + + +def build_element(payload, eid=None, ext_id=None): + if ext_id is None: + return struct.pack('BB', eid, len(payload)) + payload + return struct.pack('BBB', WLAN_EID_EXTENSION, 1 + len(payload), ext_id) + payload + + +def client_addr(frame): + addr1, addr2, bssid = frame[4:10], frame[10:16], frame[16:22] + return addr1 if addr2 == bssid else addr2 + + +def masked_fc_aad(frame, extra_mask=0): + fc = frame_fc(frame) + masked_fc = (fc & ~(IEEE80211_FCTL_RETRY | IEEE80211_FCTL_PM | + IEEE80211_FCTL_MOREDATA)) | extra_mask + return struct.pack('