From patchwork Thu Jul 2 13:14:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilan Peer X-Patchwork-Id: 490623 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) by ozlabs.org (Postfix) with ESMTP id 53ED614029E for ; Thu, 2 Jul 2015 23:17:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 59A4317C651; Thu, 2 Jul 2015 09:17:13 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2dcIE1X-B0Em; Thu, 2 Jul 2015 09:17:13 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 2FD4D17C652; Thu, 2 Jul 2015 09:15:53 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 6581517C652 for ; Thu, 2 Jul 2015 09:15:52 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uKMSJumVI+2d for ; Thu, 2 Jul 2015 09:15:48 -0400 (EDT) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id B030417C651 for ; Thu, 2 Jul 2015 09:15:29 -0400 (EDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 02 Jul 2015 06:15:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,393,1432623600"; d="scan'208";a="721729509" Received: from unknown (HELO ipeer-dev-3.jer.intel.com) ([10.12.217.137]) by orsmga001.jf.intel.com with ESMTP; 02 Jul 2015 06:15:26 -0700 From: Ilan Peer To: hostap@lists.shmoo.com Subject: [PATCH 6/9] tests: Add p2ps_provision() method Date: Thu, 2 Jul 2015 16:14:57 +0300 Message-Id: <1435842900-25523-7-git-send-email-ilan.peer@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435842900-25523-1-git-send-email-ilan.peer@intel.com> References: <1435842900-25523-1-git-send-email-ilan.peer@intel.com> X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Andrei Otcheretianski Add generic provision method. This method receives a seeker and an advertiser devices, advertisement id, method and a flag which indicates whether deferred flow is expected. The method returns P2PS-PROV-DONE events and the pin (if keypad or display method is used). This method is needed to simplify the P2PS provision flows in the tests. This method complies to the P2PS spec regarding the expected order of the show and display pin events. Signed-off-by: Andrei Otcheretianski Reviewed-by: Max Stepanov Reviewed-by: Ilan Peer --- tests/hwsim/test_p2ps.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/hwsim/test_p2ps.py b/tests/hwsim/test_p2ps.py index fadfdcf..a8b24dc 100644 --- a/tests/hwsim/test_p2ps.py +++ b/tests/hwsim/test_p2ps.py @@ -8,6 +8,7 @@ import logging logger = logging.getLogger() import time import random +import re import hwsim_utils from wpasupplicant import WpaSupplicant @@ -122,6 +123,99 @@ def p2ps_nonexact_seek(i_dev, r_dev, svc_name, srv_info=None, adv_num=None): ev_list.append(''.join([adv_id, ' ', rcvd_svc_name])) return ev_list +def p2ps_parse_event(ev, *args): + ret = () + for arg in args: + m = re.search("\s+" + arg + r"=(\S+)", ev) + ret += (m.group(1) if m is not None else None,) + return ret + +def p2ps_provision(seeker, advertiser, adv_id, auto_accept=True, method="1000"): + addr0 = seeker.p2p_dev_addr() + addr1 = advertiser.p2p_dev_addr() + + seeker.asp_provision(addr1, adv_id=str(adv_id), adv_mac=addr1, session_id=1, session_mac=addr0, method=method) + + if not auto_accept or method == "100": + pin = None + ev_pd_start = advertiser.wait_global_event(["P2PS-PROV-START"], timeout=10) + if ev_pd_start is None: + raise Exception("P2PS-PROV-START timeout on Advertiser side") + peer = ev_pd_start.split()[1] + advert_id, advert_mac, session, session_mac =\ + p2ps_parse_event(ev_pd_start, "adv_id", "adv_mac", "session", "mac") + + ev = seeker.wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-FAILURE timeout on seeker side") + + if method == "100": + ev = advertiser.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on advertiser side") + if addr0 not in ev: + raise Exception("Unknown peer " + addr0) + ev = seeker.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on seeker side") + if addr1 not in ev: + raise Exception("Unknown peer " + addr1) + pin = ev.split()[2] + elif method == "8": + ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side") + if addr0 not in ev: + raise Exception("Unknown peer " + addr0) + pin = ev.split()[2] + + advertiser.asp_provision(peer, adv_id=advert_id, adv_mac=advert_mac, session_id=int(session, 0), + session_mac=session_mac, status=12) + + ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10) + if ev1 is None: + raise Exception("P2PS-PROV-DONE timeout on seeker side") + + ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10) + if ev2 is None: + raise Exception("P2PS-PROV-DONE timeout on advertiser side") + + if method == "8": + ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-ENTER-PIN failed on seeker side") + if addr1 not in ev: + raise Exception("Unknown peer " + addr1) + + if pin is not None: + return ev1, ev2, pin + return ev1, ev2 + + # Auto-accept is true and the method is either P2PS or advertiser is DISPLAY + ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10) + if ev1 is None: + raise Exception("P2PS-PROV-DONE timeout on seeker side") + + ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10) + if ev2 is None: + raise Exception("P2PS-PROV-DONE timeout on advertiser side") + + if method == "8": + ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on seeker side") + if addr1 not in ev: + raise Exception("Unknown peer " + addr1) + ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=10) + if ev is None: + raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side") + if addr0 not in ev: + raise Exception("Unknown peer " + addr0) + pin = ev.split()[2] + return ev1, ev2, pin + + return ev1, ev2 + def p2p_connect_p2ps_method(i_dev, r_dev, autoaccept): """P2PS connect function with p2ps method""" if autoaccept == False: