From patchwork Sat Mar 9 19:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Dziedzic X-Patchwork-Id: 1910132 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=vurO9Dvk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=kiS13BdS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) 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 4TsYPD0qpsz23r4 for ; Sun, 10 Mar 2024 06:43:26 +1100 (AEDT) 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=KNyfsYy3JQS3QvMPTQaUM9U/xNGJSG05gomdUsFZxqQ=; b=vurO9DvkEYNEvC fHRsnHqsPXesDAyXt1X/kpACkDLnfgwDpN4xn/h8OS8N2AfY1dOphwfMkRF7dizcT4sEZ8L5sTBQk /UClgl9oC6fzx+w5dEbOyyTPfjenn25suDnRrbOT0H6LoRjOnA0jiAVzFGa8ySJJsnBshCGGAyHU1 Joyinbov8nwZUclyevwE/t1HyVcDLr+im3F8E3Wm0VgcIld4y7IF6GiiT3WH6dOH4g6FM5X+w21z0 FxDDAK0fG71+KqIi35HycqqQmVlPtHwHy2JbHhN6M3pX8lrz2XoG1KC52B+bRWy5grwZr4Hnx4pZa bBr868Djssa7MEK4EkZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rj2ar-0000000E6sZ-0VIp; Sat, 09 Mar 2024 19:42:53 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rj2an-0000000E6qG-2B4I for hostap@lists.infradead.org; Sat, 09 Mar 2024 19:42:51 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-56759dc7ea6so3981838a12.1 for ; Sat, 09 Mar 2024 11:42:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710013365; x=1710618165; darn=lists.infradead.org; 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=LYddR2YWaY1BNKekq71z9vaBjKE9EvgYx2PUMY5S6j4=; b=kiS13BdSB45V4eTd3wnkHYPOvbVktXKi0eYQovfnRRiqSpkwBOiHYYC0ahMAU4WtJy vCSzengqkU2fB+sKngvH0L/jVBL6mmbyoaeIOZY8T895SYgcHHNIY1HGAbFZ65CgynuT qt3sPTa+gXYCALaCc6+UvWuRJvNwQtPZb1gaXse+SrwdqLcuVWJe7YPBqsJ3x820X549 /8mpTkSevX5xiDDZ+NVFgwBzoZlPA+IMfEtGlVtMaqcJ4GQbYvWHfYj10rsDBAviUBoH OI44W97QgMQOq/Yw1NFVYgab/ubblRoEURA4GyOPJLIWFNtrHxnRDcygO8du7RDAbR8g lo6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710013365; x=1710618165; 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=LYddR2YWaY1BNKekq71z9vaBjKE9EvgYx2PUMY5S6j4=; b=mUHfCc62TxI0Nt1+ZUlRbZKbvCIHCOFR9a33O86y/OWJ0xDsWucVkBYDUzgq2naAKt 3Mio234E33EwTTlANbrOjCLegxje4fXHPwU39888JiHaMSuukiZoJK9bxnhAwxy/um6w PkfUvhuty0DxM997b471K3zcqKZp3uLMhaQR+hJzRKLEHR+i2U1OJIlQKgFWpPsqNeb2 QWrKTQnbckvGwkgd2IKSVN99qa0QA7o6bnVfN/b5yyZbqB2Qo26kwODVoGw+CLtv8eBf iGeEkwVHzvmsF9uMDKicc3IzS4V10GXC5I4nQmnGVl/x7CgJUKO0uRfD9OwZ55MIDgGT qj8Q== X-Gm-Message-State: AOJu0YwLHI+pzgM+4e3lxf6+lJ5pv7SKqpPh6G58P10TT9zYMBiag/RN 9y94ve9jlh3JgqkQtbFQFaVxvRqVzQtEmcwqJgFiB8t0xofB020WIbYovi05 X-Google-Smtp-Source: AGHT+IHjFkIJYxyOM6GAM8JU6gI0uhNQz2NPAF80NIVYlHxdG6ywDAqys7/v5hxJ49p0j7e7wtszJg== X-Received: by 2002:a50:9305:0:b0:566:d25e:b73c with SMTP id m5-20020a509305000000b00566d25eb73cmr1944726eda.35.1710013365128; Sat, 09 Mar 2024 11:42:45 -0800 (PST) Received: from e850.lan ([62.141.192.106]) by smtp.gmail.com with ESMTPSA id y2-20020aa7c242000000b0056740ba5eb0sm1206107edo.37.2024.03.09.11.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 11:42:44 -0800 (PST) From: Janusz Dziedzic To: hostap@lists.infradead.org Cc: j@w1.fi, Janusz Dziedzic Subject: [PATCH 2/7] wpaspy: add option to use wpa_cli Date: Sat, 9 Mar 2024 20:42:23 +0100 Message-Id: <20240309194228.4186699-2-janusz.dziedzic@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240309194228.4186699-1-janusz.dziedzic@gmail.com> References: <20240309194228.4186699-1-janusz.dziedzic@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240309_114249_592605_B85720B2 X-CRM114-Status: GOOD ( 12.61 ) X-Spam-Score: -0.2 (/) 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: This one allow connection to remote/local host via SSH and use wpa_cli. Signed-off-by: Janusz Dziedzic --- wpaspy/wpaspy.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:52a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [janusz.dziedzic(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 This one allow connection to remote/local host via SSH and use wpa_cli. Signed-off-by: Janusz Dziedzic --- wpaspy/wpaspy.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/wpaspy/wpaspy.py b/wpaspy/wpaspy.py index 5b8140b7c..ae305c8d5 100644 --- a/wpaspy/wpaspy.py +++ b/wpaspy/wpaspy.py @@ -10,16 +10,26 @@ import os import stat import socket import select +import remotehost counter = 0 class Ctrl: - def __init__(self, path, port=9877): + def __init__(self, path, port=9877, hostname=None, ifname=None): global counter self.started = False self.attached = False self.path = path self.port = port + self.ifname = ifname + self.host = None + self.proc = None + self.hostname = hostname + + if hostname: + self.host = remotehost.Host(hostname) + self.started = True + return self.udp = False if not path.startswith('/'): @@ -74,6 +84,11 @@ class Ctrl: # Need to ignore this allow the socket to be closed self.attached = False pass + + if self.host and self.started: + self.started = False + return + if self.started: self.s.close() if not self.udp: @@ -81,6 +96,15 @@ class Ctrl: self.started = False def request(self, cmd, timeout=10): + if self.host: + cmd = '\'' + cmd + '\'' + if self.ifname: + _cmd = ['wpa_cli', '-p', self.path, '-i', self.ifname, "raw " + cmd] + else: + _cmd = ['wpa_cli', '-g', self.path, "raw " + cmd] + status, buf = self.host.execute(_cmd) + return buf + if type(cmd) == str: try: cmd2 = cmd.encode() @@ -104,6 +128,16 @@ class Ctrl: def attach(self): if self.attached: return None + + if self.host: + if self.ifname: + _cmd = [ "wpa_cli", "-p", self.path, "-i", self.ifname ] + else: + _cmd = [ "wpa_cli", '-g', self.path] + self.proc = self.host.proc_run(_cmd) + self.attached = True + return + res = self.request("ATTACH") if "OK" in res: self.attached = True @@ -113,6 +147,15 @@ class Ctrl: def detach(self): if not self.attached: return None + + if self.hostname and self.proc: + self.request("DETACH") + self.request("QUIT") + self.host.proc_stop(self.proc) + self.attached = False + self.proc = None + return None + if self.s.fileno() == -1: self.attached = False return None @@ -135,12 +178,19 @@ class Ctrl: self.close() def pending(self, timeout=0): + if self.host and self.proc: + return self.host.proc_pending(self.proc, timeout=timeout) + [r, w, e] = select.select([self.s], [], [], timeout) if r: return True return False def recv(self): + if self.host and self.proc: + res = self.host.proc_read(self.proc) + return res + res = self.s.recv(4096).decode() try: r = str(res)