2013-03-09 15:30:25 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# P2P autonomous GO 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.
|
|
|
|
|
2013-03-09 17:24:32 +01:00
|
|
|
import time
|
2013-03-09 18:01:56 +01:00
|
|
|
import subprocess
|
2013-03-09 15:30:25 +01:00
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
import hwsim_utils
|
2013-04-01 09:37:44 +02:00
|
|
|
from wlantest import Wlantest
|
2013-03-09 15:30:25 +01:00
|
|
|
|
2013-03-09 16:51:22 +01:00
|
|
|
def autogo(go):
|
2013-03-09 15:30:25 +01:00
|
|
|
logger.info("Start autonomous GO " + go.ifname)
|
|
|
|
res = go.p2p_start_go()
|
|
|
|
logger.debug("res: " + str(res))
|
2013-09-29 11:42:05 +02:00
|
|
|
return res
|
2013-03-09 15:30:25 +01:00
|
|
|
|
2013-03-09 16:51:22 +01:00
|
|
|
def connect_cli(go, client):
|
2013-03-09 15:30:25 +01:00
|
|
|
logger.info("Try to connect the client to the GO")
|
|
|
|
pin = client.wps_read_pin()
|
|
|
|
go.p2p_go_authorize_client(pin)
|
|
|
|
client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60)
|
2013-03-09 16:51:22 +01:00
|
|
|
logger.info("Client connected")
|
2013-03-09 15:30:25 +01:00
|
|
|
hwsim_utils.test_connectivity_p2p(go, client)
|
|
|
|
|
|
|
|
def test_autogo(dev):
|
2013-03-17 10:19:24 +01:00
|
|
|
"""P2P autonomous GO and client joining group"""
|
2013-03-09 16:51:22 +01:00
|
|
|
autogo(dev[0])
|
|
|
|
connect_cli(dev[0], dev[1])
|
2013-03-09 15:30:25 +01:00
|
|
|
dev[0].remove_group()
|
2013-09-01 18:30:08 +02:00
|
|
|
dev[1].wait_go_ending_session()
|
2013-03-09 15:30:25 +01:00
|
|
|
|
2013-03-09 16:51:22 +01:00
|
|
|
def test_autogo_2cli(dev):
|
2013-03-17 10:19:24 +01:00
|
|
|
"""P2P autonomous GO and two clients joining group"""
|
2013-03-09 16:51:22 +01:00
|
|
|
autogo(dev[0])
|
|
|
|
connect_cli(dev[0], dev[1])
|
|
|
|
connect_cli(dev[0], dev[2])
|
|
|
|
hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
|
2013-09-01 16:58:17 +02:00
|
|
|
dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr())
|
2013-09-01 18:30:08 +02:00
|
|
|
dev[1].wait_go_ending_session()
|
2013-03-09 16:51:22 +01:00
|
|
|
dev[0].remove_group()
|
2013-09-01 18:30:08 +02:00
|
|
|
dev[2].wait_go_ending_session()
|
2013-03-09 16:51:22 +01:00
|
|
|
|
2013-03-09 17:24:32 +01:00
|
|
|
def test_autogo_tdls(dev):
|
2013-03-17 10:19:24 +01:00
|
|
|
"""P2P autonomous GO and two clients using TDLS"""
|
2013-04-01 09:37:44 +02:00
|
|
|
wt = Wlantest()
|
2013-03-09 18:01:56 +01:00
|
|
|
go = dev[0]
|
|
|
|
logger.info("Start autonomous GO with fixed parameters " + go.ifname)
|
|
|
|
id = go.add_network()
|
|
|
|
go.set_network_quoted(id, "ssid", "DIRECT-tdls")
|
|
|
|
go.set_network_quoted(id, "psk", "12345678")
|
|
|
|
go.set_network(id, "mode", "3")
|
|
|
|
go.set_network(id, "disabled", "2")
|
|
|
|
res = go.p2p_start_go(persistent=id)
|
|
|
|
logger.debug("res: " + str(res))
|
2013-04-01 09:37:44 +02:00
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2013-03-09 18:01:56 +01:00
|
|
|
connect_cli(go, dev[1])
|
|
|
|
connect_cli(go, dev[2])
|
2013-03-09 17:24:32 +01:00
|
|
|
hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
|
2013-03-09 18:01:56 +01:00
|
|
|
bssid = dev[0].p2p_interface_addr()
|
|
|
|
addr1 = dev[1].p2p_interface_addr()
|
2013-03-09 17:24:32 +01:00
|
|
|
addr2 = dev[2].p2p_interface_addr()
|
|
|
|
dev[1].tdls_setup(addr2)
|
|
|
|
time.sleep(1)
|
|
|
|
hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
|
2013-04-01 09:37:44 +02:00
|
|
|
conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
|
2013-03-09 18:01:56 +01:00
|
|
|
if conf == 0:
|
|
|
|
raise Exception("No TDLS Setup Confirm (success) seen")
|
2013-04-01 09:37:44 +02:00
|
|
|
dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
|
2013-03-09 18:01:56 +01:00
|
|
|
if dl == 0:
|
|
|
|
raise Exception("No valid frames through direct link")
|
2013-04-01 09:37:44 +02:00
|
|
|
wt.tdls_clear(bssid, addr1, addr2);
|
2013-03-09 17:24:32 +01:00
|
|
|
dev[1].tdls_teardown(addr2)
|
|
|
|
time.sleep(1)
|
2013-04-01 09:37:44 +02:00
|
|
|
teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
|
2013-03-27 12:32:36 +01:00
|
|
|
if teardown == 0:
|
2013-03-09 18:01:56 +01:00
|
|
|
raise Exception("No TDLS Setup Teardown seen")
|
2013-04-01 09:37:44 +02:00
|
|
|
wt.tdls_clear(bssid, addr1, addr2);
|
2013-03-09 17:24:32 +01:00
|
|
|
hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
|
2013-04-01 09:37:44 +02:00
|
|
|
ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
|
2013-03-09 18:01:56 +01:00
|
|
|
if ap_path == 0:
|
|
|
|
raise Exception("No valid frames via AP path")
|
2013-04-01 09:37:44 +02:00
|
|
|
direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
|
2013-03-09 18:01:56 +01:00
|
|
|
if direct_link > 0:
|
|
|
|
raise Exception("Unexpected frames through direct link")
|
2013-04-01 09:37:44 +02:00
|
|
|
idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
|
|
|
|
addr2);
|
2013-03-09 18:01:56 +01:00
|
|
|
if idirect_link > 0:
|
|
|
|
raise Exception("Unexpected frames through direct link (invalid)")
|
2013-03-09 17:24:32 +01:00
|
|
|
dev[2].remove_group()
|
|
|
|
dev[1].remove_group()
|
|
|
|
dev[0].remove_group()
|
2013-09-29 11:42:05 +02:00
|
|
|
|
|
|
|
def test_autogo_legacy(dev):
|
|
|
|
"""P2P autonomous GO and legacy clients"""
|
|
|
|
res = autogo(dev[0])
|
|
|
|
|
|
|
|
logger.info("Connect P2P client")
|
|
|
|
connect_cli(dev[0], dev[1])
|
|
|
|
|
|
|
|
logger.info("Connect legacy WPS client")
|
|
|
|
pin = dev[2].wps_read_pin()
|
|
|
|
dev[0].p2p_go_authorize_client(pin)
|
|
|
|
dev[2].request("SET ignore_old_scan_res 1")
|
|
|
|
dev[2].request("P2P_SET disabled 1")
|
|
|
|
dev[2].dump_monitor()
|
|
|
|
dev[2].request("WPS_PIN any " + pin)
|
|
|
|
ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Association with the GO timed out")
|
|
|
|
status = dev[2].get_status()
|
|
|
|
if status['wpa_state'] != 'COMPLETED':
|
|
|
|
raise Exception("Not fully connected")
|
|
|
|
hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
|
|
|
|
dev[2].request("DISCONNECT")
|
|
|
|
|
|
|
|
logger.info("Connect legacy non-WPS client")
|
|
|
|
dev[2].request("FLUSH")
|
|
|
|
dev[2].request("P2P_SET disabled 1")
|
|
|
|
dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
|
|
|
|
key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
|
|
|
|
scan_freq=res['freq'])
|
|
|
|
hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
|
|
|
|
dev[2].request("DISCONNECT")
|
|
|
|
|
|
|
|
dev[0].remove_group()
|
|
|
|
dev[1].wait_go_ending_session()
|