tests: Report group formation results as a dict
Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
a311c61dd6
commit
c68f9a61c6
2 changed files with 40 additions and 8 deletions
|
@ -17,7 +17,10 @@ def go_neg_pin_authorized(i_dev, r_dev, i_intent=7, r_intent=7):
|
|||
pin = r_dev.wps_read_pin()
|
||||
logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
|
||||
r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, "display")
|
||||
i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, "enter", timeout=15)
|
||||
i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, "enter", timeout=15)
|
||||
r_res = r_dev.p2p_go_neg_auth_result()
|
||||
logger.debug("i_res: " + str(i_res))
|
||||
logger.debug("r_res: " + str(r_res))
|
||||
r_dev.dump_monitor()
|
||||
i_dev.dump_monitor()
|
||||
logger.info("Group formed")
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import os
|
||||
import time
|
||||
import logging
|
||||
import re
|
||||
import wpaspy
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -81,6 +82,26 @@ class WpaSupplicant:
|
|||
return True
|
||||
return False
|
||||
|
||||
def group_form_result(self, ev):
|
||||
exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)'
|
||||
s = re.split(exp, ev)
|
||||
if len(s) < 8:
|
||||
raise Exception("Could not parse P2P-GROUP-STARTED")
|
||||
res = {}
|
||||
res['result'] = 'success'
|
||||
res['ifname'] = s[2]
|
||||
res['role'] = s[3]
|
||||
res['ssid'] = s[4]
|
||||
res['freq'] = s[5]
|
||||
p = re.match(r'psk=([0-9a-f]*)', s[6])
|
||||
if p:
|
||||
res['psk'] = p.group(1)
|
||||
p = re.match(r'passphrase="(.*)"', s[6])
|
||||
if p:
|
||||
res['passphrase'] = p.group(1)
|
||||
res['go_dev_addr'] = s[7]
|
||||
return res
|
||||
|
||||
def p2p_go_neg_auth(self, peer, pin, method):
|
||||
if not self.discover_peer(peer):
|
||||
raise Exception("Peer " + peer + " not found")
|
||||
|
@ -90,6 +111,13 @@ class WpaSupplicant:
|
|||
return None
|
||||
raise Exception("P2P_CONNECT (auth) failed")
|
||||
|
||||
def p2p_go_neg_auth_result(self, timeout=1):
|
||||
ev = self.wait_event("P2P-GROUP-STARTED", timeout);
|
||||
if ev is None:
|
||||
raise Exception("Group formation timed out")
|
||||
self.dump_monitor()
|
||||
return self.group_form_result(ev)
|
||||
|
||||
def p2p_go_neg_init(self, peer, pin, method, timeout=0):
|
||||
if not self.discover_peer(peer):
|
||||
raise Exception("Peer " + peer + " not found")
|
||||
|
@ -99,22 +127,23 @@ class WpaSupplicant:
|
|||
if timeout == 0:
|
||||
self.dump_monitor()
|
||||
return None
|
||||
if self.wait_event("P2P-GROUP-STARTED", timeout):
|
||||
self.dump_monitor()
|
||||
return None
|
||||
ev = self.wait_event("P2P-GROUP-STARTED", timeout)
|
||||
if ev is None:
|
||||
raise Exception("Group formation timed out")
|
||||
self.dump_monitor()
|
||||
return self.group_form_result(ev)
|
||||
raise Exception("P2P_CONNECT failed")
|
||||
|
||||
def wait_event(self, event, timeout):
|
||||
count = 0
|
||||
while count < timeout * 2:
|
||||
count = count + 1
|
||||
time.sleep(0.5)
|
||||
time.sleep(0.1)
|
||||
while self.mon.pending():
|
||||
ev = self.mon.recv()
|
||||
if event in ev:
|
||||
return True
|
||||
return False
|
||||
return ev
|
||||
return None
|
||||
|
||||
def dump_monitor(self):
|
||||
while self.mon.pending():
|
||||
|
|
Loading…
Reference in a new issue