From patchwork Fri Feb 26 09:38:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 588722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 90DCA140271 for ; Fri, 26 Feb 2016 20:40:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tieto.com header.i=@tieto.com header.b=zE1Khkq2; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZEsV-0004cH-LL; Fri, 26 Feb 2016 09:40:03 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZEsA-0004Hf-4l for hostap@bombadil.infradead.org; Fri, 26 Feb 2016 09:39:42 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by merlin.infradead.org with esmtps (Exim 4.85 #2 (Red Hat Linux)) id 1aZEs8-000575-Qk for hostap@lists.infradead.org; Fri, 26 Feb 2016 09:39:41 +0000 Received: by mail-wm0-x235.google.com with SMTP id g62so64769542wme.1 for ; Fri, 26 Feb 2016 01:39:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wcsybh/OW0UFGSlrLMetblFx4Cyu7khETCJODS0dGt0=; b=zE1Khkq2PU1FJtDrbGWYbJpntTf2CjBKE+LhvXr5b1cJM8351wOOpTqY268F6Mz6Pv PkVwpswZOFzWZxoY549qKtlc2FiDMdPavrFQsql7yCEuIcbjnOi2wJNTFK8WzuILOA7m j13Cas5qta1sRZif8a05CcmJD2LSGQ8wIYal4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wcsybh/OW0UFGSlrLMetblFx4Cyu7khETCJODS0dGt0=; b=WjA+NrMqbhmf9VnfjOoy0YVoyvmNGRMwxIKw6AxSseJxNjKr33/RzBBW94b25rRwDK etguu+PN6KZGQv85GlB4zIvA7FiYy+/5JrpfNr/ceUUrgLZLiDF0BgB9YXgvQDKEa+6I 4vQdm6xdiOzzg/qMaWzFGGmpqG1WiaQFDeEvRtmx++xioLZQ87iq1lrKmx6/VFgz+D47 C5byEuXGlRmkv86l54RQMWl2Tg2N1MUJTC0IKsd3hpADWotC+oCcc1C3185UkucGuQ+A SuujToyZXrt1t/PCIZAU4pfTc6J+aYvUoMZB8kFXLT82k9aeGcjsA/Vb1gM5KB1P7kgD L/4g== X-Gm-Message-State: AD7BkJIOayOnNMAKB6fkIKtzf5cakTwd55Kh+xcsStk+4/LVmQjaTh2q22F3CK0wEPwEyqAgIvc6Dig35TOhI7BPZcovkY/YxqqfcZQ+VJZ4sN6l0k3kpMwia2Ft892BfcP7HtVgKp1qnJWLRPGXsR96cTVTeYlCQgzVEwoI9ozXMdbhsPqlJzPUiq7P5DVeSfCA X-Received: by 10.28.183.137 with SMTP id h131mr2172000wmf.100.1456479558870; Fri, 26 Feb 2016 01:39:18 -0800 (PST) Received: from dell6430.guest.wifi ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id z65sm1915950wmg.1.2016.02.26.01.39.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 01:39:18 -0800 (PST) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH v4 18/29] tests: wpasupplicant.py allow to use remote host Date: Fri, 26 Feb 2016 10:38:33 +0100 Message-Id: <1456479524-14185-19-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456479524-14185-1-git-send-email-janusz.dziedzic@tieto.com> References: <1456479524-14185-1-git-send-email-janusz.dziedzic@tieto.com> X-DomainID: tieto.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160226_043941_003742_DD4E3FB2 X-CRM114-Status: UNSURE ( 9.26 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:235 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Janusz Dziedzic MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Allow to use remote host using wpaspy.Ctrl with UDP support. Signed-off-by: Janusz Dziedzic --- tests/hwsim/wpasupplicant.py | 46 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 13a93ec..8003467 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -17,18 +17,23 @@ logger = logging.getLogger() wpas_ctrl = '/var/run/wpa_supplicant' class WpaSupplicant: - def __init__(self, ifname=None, global_iface=None): + def __init__(self, ifname=None, global_iface=None, hostname=None, port=9877, global_port=9878): + self.hostname = hostname self.group_ifname = None self.gctrl_mon = None if ifname: - self.set_ifname(ifname) + self.set_ifname(ifname, hostname, port) else: self.ifname = None self.global_iface = global_iface if global_iface: - self.global_ctrl = wpaspy.Ctrl(global_iface) - self.global_mon = wpaspy.Ctrl(global_iface) + if hostname != None: + self.global_ctrl = wpaspy.Ctrl(hostname, global_port) + self.global_mon = wpaspy.Ctrl(hostname, global_port) + else: + self.global_ctrl = wpaspy.Ctrl(global_iface) + self.global_mon = wpaspy.Ctrl(global_iface) self.global_mon.attach() else: self.global_mon = None @@ -40,10 +45,14 @@ class WpaSupplicant: self.global_ctrl = None self.remove_ifname() - def set_ifname(self, ifname): + def set_ifname(self, ifname, hostname=None, port=9877): self.ifname = ifname - self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname)) - self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname)) + if hostname != None: + self.ctrl = wpaspy.Ctrl(hostname, port) + self.mon = wpaspy.Ctrl(hostname, port) + else: + self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname)) + self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname)) self.mon.attach() def remove_ifname(self): @@ -53,6 +62,26 @@ class WpaSupplicant: self.ctrl = None self.ifname = None + def get_ctrl_iface_port(self, ifname): + res = -1 + if self.hostname is None: + return None + + res = self.global_request("INTERFACES ctrl") + lines = res.splitlines() + for line in lines: + words = line.split() + if words[0] == ifname: + res = 1 + break + if res == -1: + raise Exception("Could not find UDP port for " + ifname) + res = line.find("ctrl_iface=udp:") + if res == -1: + raise Exception("Wrong ctrl_interace format") + words = line.split(":") + return int(words[1]) + def interface_add(self, ifname, config="", driver="nl80211", drv_params=None, br_ifname=None, create=False, set_ifname=True, all_params=False, if_type=None): @@ -85,7 +114,8 @@ class WpaSupplicant: if "FAIL" in self.global_request(cmd): raise Exception("Failed to add a dynamic wpa_supplicant interface") if not create and set_ifname: - self.set_ifname(ifname) + port = self.get_ctrl_iface_port(ifname) + self.set_ifname(ifname, self.hostname, port) def interface_remove(self, ifname): self.remove_ifname()