2013-03-02 05:22:28 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# P2P group formation 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-16 05:36:59 -04:00
|
|
|
import time
|
|
|
|
import threading
|
|
|
|
import Queue
|
2013-03-02 05:22:28 -05:00
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
|
2013-03-17 05:10:59 -04:00
|
|
|
def check_grpform_results(i_res, r_res):
|
|
|
|
if i_res['result'] != 'success' or r_res['result'] != 'success':
|
|
|
|
raise Exception("Failed group formation")
|
|
|
|
if i_res['ssid'] != r_res['ssid']:
|
|
|
|
raise Exception("SSID mismatch")
|
|
|
|
if i_res['freq'] != r_res['freq']:
|
|
|
|
raise Exception("SSID mismatch")
|
|
|
|
if i_res['go_dev_addr'] != r_res['go_dev_addr']:
|
|
|
|
raise Exception("GO Device Address mismatch")
|
|
|
|
|
2013-03-16 05:36:59 -04:00
|
|
|
def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res):
|
|
|
|
logger.debug("Initiate GO Negotiation from i_dev")
|
2013-08-31 03:33:44 -04:00
|
|
|
i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent)
|
2013-03-16 05:36:59 -04:00
|
|
|
logger.debug("i_res: " + str(i_res))
|
|
|
|
res.put(i_res)
|
|
|
|
|
|
|
|
def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'):
|
|
|
|
r_dev.p2p_listen()
|
|
|
|
i_dev.p2p_listen()
|
|
|
|
pin = r_dev.wps_read_pin()
|
|
|
|
logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
|
|
|
|
r_dev.dump_monitor()
|
|
|
|
res = Queue.Queue()
|
|
|
|
t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res))
|
|
|
|
t.start()
|
|
|
|
logger.debug("Wait for GO Negotiation Request on r_dev")
|
2013-06-30 17:13:11 -04:00
|
|
|
ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
|
2013-03-16 05:36:59 -04:00
|
|
|
if ev is None:
|
|
|
|
raise Exception("GO Negotiation timed out")
|
|
|
|
r_dev.dump_monitor()
|
|
|
|
logger.debug("Re-initiate GO Negotiation from r_dev")
|
2013-08-31 03:33:44 -04:00
|
|
|
r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20)
|
2013-03-16 05:36:59 -04:00
|
|
|
logger.debug("r_res: " + str(r_res))
|
|
|
|
r_dev.dump_monitor()
|
|
|
|
t.join()
|
|
|
|
i_res = res.get()
|
|
|
|
logger.debug("i_res: " + str(i_res))
|
|
|
|
logger.info("Group formed")
|
|
|
|
hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
|
|
|
|
i_dev.dump_monitor()
|
|
|
|
|
2013-03-09 09:00:43 -05:00
|
|
|
def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None, i_method='enter', r_method='display'):
|
2013-03-02 05:22:28 -05:00
|
|
|
r_dev.p2p_listen()
|
|
|
|
i_dev.p2p_listen()
|
|
|
|
pin = r_dev.wps_read_pin()
|
|
|
|
logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
|
2013-03-09 09:00:43 -05:00
|
|
|
r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent)
|
2013-08-31 03:33:44 -04:00
|
|
|
i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, expect_failure=expect_failure)
|
2013-03-09 06:52:59 -05:00
|
|
|
r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
|
2013-03-09 06:36:35 -05:00
|
|
|
logger.debug("i_res: " + str(i_res))
|
|
|
|
logger.debug("r_res: " + str(r_res))
|
2013-03-02 05:22:28 -05:00
|
|
|
r_dev.dump_monitor()
|
|
|
|
i_dev.dump_monitor()
|
2013-03-09 08:52:57 -05:00
|
|
|
if i_go_neg_status:
|
|
|
|
if i_res['result'] != 'go-neg-failed':
|
|
|
|
raise Exception("Expected GO Negotiation failure not reported")
|
|
|
|
if i_res['status'] != i_go_neg_status:
|
|
|
|
raise Exception("Expected GO Negotiation status not seen")
|
2013-03-09 06:52:59 -05:00
|
|
|
if expect_failure:
|
|
|
|
return
|
2013-03-02 05:22:28 -05:00
|
|
|
logger.info("Group formed")
|
|
|
|
hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
|
|
|
|
|
2013-03-17 05:10:59 -04:00
|
|
|
def go_neg_init_pbc(i_dev, r_dev, i_intent, res):
|
|
|
|
logger.debug("Initiate GO Negotiation from i_dev")
|
2013-08-31 03:33:44 -04:00
|
|
|
i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc", timeout=20, go_intent=i_intent)
|
2013-03-17 05:10:59 -04:00
|
|
|
logger.debug("i_res: " + str(i_res))
|
|
|
|
res.put(i_res)
|
|
|
|
|
|
|
|
def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None):
|
2013-03-18 11:36:12 -04:00
|
|
|
r_dev.p2p_find(social=True)
|
|
|
|
i_dev.p2p_find(social=True)
|
2013-03-17 05:10:59 -04:00
|
|
|
logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
|
|
|
|
r_dev.dump_monitor()
|
|
|
|
res = Queue.Queue()
|
|
|
|
t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res))
|
|
|
|
t.start()
|
|
|
|
logger.debug("Wait for GO Negotiation Request on r_dev")
|
2013-06-30 17:13:11 -04:00
|
|
|
ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
|
2013-03-17 05:10:59 -04:00
|
|
|
if ev is None:
|
|
|
|
raise Exception("GO Negotiation timed out")
|
|
|
|
r_dev.dump_monitor()
|
|
|
|
logger.debug("Re-initiate GO Negotiation from r_dev")
|
2013-08-31 03:33:44 -04:00
|
|
|
r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", go_intent=r_intent, timeout=20)
|
2013-03-17 05:10:59 -04:00
|
|
|
logger.debug("r_res: " + str(r_res))
|
|
|
|
r_dev.dump_monitor()
|
|
|
|
t.join()
|
|
|
|
i_res = res.get()
|
|
|
|
logger.debug("i_res: " + str(i_res))
|
|
|
|
logger.info("Group formed")
|
|
|
|
hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
|
|
|
|
i_dev.dump_monitor()
|
|
|
|
return [i_res, r_res]
|
|
|
|
|
2013-03-02 05:22:28 -05:00
|
|
|
def test_grpform(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P group formation using PIN and authorized connection (init -> GO)"""
|
2013-03-02 05:22:28 -05:00
|
|
|
go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
|
|
|
|
dev[0].remove_group()
|
|
|
|
try:
|
|
|
|
dev[1].remove_group()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_grpform2(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P group formation using PIN and authorized connection (resp -> GO)"""
|
2013-03-02 05:22:28 -05:00
|
|
|
go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
|
|
|
|
dev[0].remove_group()
|
|
|
|
try:
|
|
|
|
dev[1].remove_group()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2013-03-16 05:36:59 -04:00
|
|
|
def test_grpform3(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P group formation using PIN and re-init GO Negotiation"""
|
2013-03-16 05:36:59 -04:00
|
|
|
go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
|
|
|
|
dev[0].remove_group()
|
|
|
|
try:
|
|
|
|
dev[1].remove_group()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2013-03-17 05:10:59 -04:00
|
|
|
def test_grpform_pbc(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P group formation using PBC and re-init GO Negotiation"""
|
2013-03-17 05:10:59 -04:00
|
|
|
[i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
|
|
|
|
check_grpform_results(i_res, r_res)
|
|
|
|
if i_res['role'] != 'GO' or r_res['role'] != 'client':
|
|
|
|
raise Exception("Unexpected device roles")
|
|
|
|
dev[0].remove_group()
|
|
|
|
try:
|
|
|
|
dev[1].remove_group()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2013-03-09 06:52:59 -05:00
|
|
|
def test_both_go_intent_15(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P GO Negotiation with both devices using GO intent 15"""
|
2013-03-09 08:52:57 -05:00
|
|
|
go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=15, expect_failure=True, i_go_neg_status=9)
|
2013-03-09 06:52:59 -05:00
|
|
|
|
2013-03-09 09:00:43 -05:00
|
|
|
def test_both_go_neg_display(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P GO Negotiation with both devices trying to display PIN"""
|
2013-03-09 09:00:43 -05:00
|
|
|
go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='display', r_method='display')
|
|
|
|
|
|
|
|
def test_both_go_neg_enter(dev):
|
2013-03-17 05:19:24 -04:00
|
|
|
"""P2P GO Negotiation with both devices trying to enter PIN"""
|
2013-03-09 09:00:43 -05:00
|
|
|
go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='enter', r_method='enter')
|