2013-03-17 09:58:48 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# P2P device discovery test cases
|
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2013-03-30 19:16:30 +01:00
|
|
|
import hwsim_utils
|
|
|
|
|
2013-03-17 09:58:48 +01:00
|
|
|
def test_discovery(dev):
|
2013-03-17 10:19:24 +01:00
|
|
|
"""P2P device discovery and provision discovery"""
|
2013-03-17 09:58:48 +01:00
|
|
|
addr0 = dev[0].p2p_dev_addr()
|
|
|
|
addr1 = dev[1].p2p_dev_addr()
|
|
|
|
logger.info("Start device discovery")
|
2013-03-18 16:36:12 +01:00
|
|
|
dev[0].p2p_find(social=True)
|
2013-03-30 19:31:22 +01:00
|
|
|
if not dev[1].discover_peer(addr0):
|
2013-03-17 09:58:48 +01:00
|
|
|
raise Exception("Device discovery timed out")
|
2013-03-30 19:31:22 +01:00
|
|
|
if not dev[0].discover_peer(addr1):
|
2013-03-17 09:58:48 +01:00
|
|
|
raise Exception("Device discovery timed out")
|
|
|
|
|
|
|
|
logger.info("Test provision discovery for display")
|
2013-06-30 23:13:11 +02:00
|
|
|
dev[0].global_request("P2P_PROV_DISC " + addr1 + " display")
|
|
|
|
ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15)
|
2013-03-17 09:58:48 +01:00
|
|
|
if ev1 is None:
|
2013-03-30 15:10:04 +01:00
|
|
|
raise Exception("Provision discovery timed out (display/dev1)")
|
2013-03-17 09:58:48 +01:00
|
|
|
if addr0 not in ev1:
|
|
|
|
raise Exception("Dev0 not in provision discovery event")
|
2013-06-30 23:13:11 +02:00
|
|
|
ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN",
|
|
|
|
"P2P-PROV-DISC-FAILURE"], timeout=15)
|
2013-03-17 09:58:48 +01:00
|
|
|
if ev0 is None:
|
2013-03-30 15:10:04 +01:00
|
|
|
raise Exception("Provision discovery timed out (display/dev0)")
|
|
|
|
if "P2P-PROV-DISC-FAILURE" in ev0:
|
|
|
|
raise Exception("Provision discovery failed (display/dev0)")
|
2013-03-17 09:58:48 +01:00
|
|
|
if addr1 not in ev0:
|
|
|
|
raise Exception("Dev1 not in provision discovery event")
|
|
|
|
|
|
|
|
logger.info("Test provision discovery for keypad")
|
2013-06-30 23:13:11 +02:00
|
|
|
dev[0].global_request("P2P_PROV_DISC " + addr1 + " keypad")
|
|
|
|
ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=15)
|
2013-03-17 09:58:48 +01:00
|
|
|
if ev1 is None:
|
2013-03-30 15:10:04 +01:00
|
|
|
raise Exception("Provision discovery timed out (keypad/dev1)")
|
2013-03-17 09:58:48 +01:00
|
|
|
if addr0 not in ev1:
|
|
|
|
raise Exception("Dev0 not in provision discovery event")
|
2013-06-30 23:13:11 +02:00
|
|
|
ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN",
|
|
|
|
"P2P-PROV-DISC-FAILURE"],
|
|
|
|
timeout=15)
|
2013-03-17 09:58:48 +01:00
|
|
|
if ev0 is None:
|
2013-03-30 15:10:04 +01:00
|
|
|
raise Exception("Provision discovery timed out (keypad/dev0)")
|
|
|
|
if "P2P-PROV-DISC-FAILURE" in ev0:
|
|
|
|
raise Exception("Provision discovery failed (keypad/dev0)")
|
2013-03-17 09:58:48 +01:00
|
|
|
if addr1 not in ev0:
|
|
|
|
raise Exception("Dev1 not in provision discovery event")
|
|
|
|
|
|
|
|
logger.info("Test provision discovery for push button")
|
2013-06-30 23:13:11 +02:00
|
|
|
dev[0].global_request("P2P_PROV_DISC " + addr1 + " pbc")
|
|
|
|
ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15)
|
2013-03-17 09:58:48 +01:00
|
|
|
if ev1 is None:
|
2013-03-30 15:10:04 +01:00
|
|
|
raise Exception("Provision discovery timed out (pbc/dev1)")
|
2013-03-17 09:58:48 +01:00
|
|
|
if addr0 not in ev1:
|
|
|
|
raise Exception("Dev0 not in provision discovery event")
|
2013-06-30 23:13:11 +02:00
|
|
|
ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP",
|
|
|
|
"P2P-PROV-DISC-FAILURE"],
|
|
|
|
timeout=15)
|
2013-03-17 09:58:48 +01:00
|
|
|
if ev0 is None:
|
2013-03-30 15:10:04 +01:00
|
|
|
raise Exception("Provision discovery timed out (pbc/dev0)")
|
|
|
|
if "P2P-PROV-DISC-FAILURE" in ev0:
|
|
|
|
raise Exception("Provision discovery failed (pbc/dev0)")
|
2013-03-17 09:58:48 +01:00
|
|
|
if addr1 not in ev0:
|
|
|
|
raise Exception("Dev1 not in provision discovery event")
|
|
|
|
|
|
|
|
dev[0].p2p_stop_find
|
|
|
|
dev[1].p2p_stop_find
|
2013-03-30 19:16:30 +01:00
|
|
|
|
|
|
|
def test_discovery_group_client(dev):
|
|
|
|
"""P2P device discovery for a client in a group"""
|
|
|
|
logger.info("Start autonomous GO " + dev[0].ifname)
|
|
|
|
res = dev[0].p2p_start_go(freq="2422")
|
|
|
|
logger.debug("res: " + str(res))
|
|
|
|
logger.info("Connect a client to the GO")
|
|
|
|
pin = dev[1].wps_read_pin()
|
|
|
|
dev[0].p2p_go_authorize_client(pin)
|
|
|
|
dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
|
|
|
|
logger.info("Client connected")
|
|
|
|
hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
|
|
|
|
logger.info("Try to discover a P2P client in a group")
|
|
|
|
if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False):
|
|
|
|
raise Exception("Could not discover group client")
|