Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / tests / hwsim / test_p2p_set.py
1 # P2P_SET test cases
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 def test_p2p_set(dev):
8     """P2P_SET commands"""
9     for cmd in [ "",
10                  "foo bar",
11                  "noa 1",
12                  "noa 1,2",
13                  "noa 1,2,3",
14                  "noa -1,0,0",
15                  "noa 256,0,0",
16                  "noa 0,-1,0",
17                  "noa 0,0,-1",
18                  "noa 0,0,1",
19                  "noa 255,10,20",
20                  "ps 1",
21                  "ps 2",
22                  "oppps 1",
23                  "ctwindow 1",
24                  "conc_pref foo",
25                  "peer_filter foo",
26                  "client_apsd 0",
27                  "client_apsd 0,0",
28                  "client_apsd 0,0,0",
29                  "disc_int 1",
30                  "disc_int 1 2",
31                  "disc_int 2 1 10",
32                  "disc_int -1 0 10",
33                  "disc_int 0 -1 10",
34                  "ssid_postfix 123456789012345678901234" ]:
35         if "FAIL" not in dev[0].request("P2P_SET " + cmd):
36             raise Exception("Invalid P2P_SET accepted: " + cmd)
37
38 def test_p2p_set_discoverability(dev):
39     """P2P_SET discoverability"""
40     addr0 = dev[0].p2p_dev_addr()
41     addr1 = dev[1].p2p_dev_addr()
42
43     dev[0].p2p_start_go(freq="2412")
44     if "OK" not in dev[1].request("P2P_SET discoverability 0"):
45         raise Exception("P2P_SET discoverability 0 failed")
46     pin = dev[1].wps_read_pin()
47     dev[0].p2p_go_authorize_client(pin)
48     dev[1].p2p_connect_group(addr0, pin, timeout=20, social=True, freq="2412")
49
50     if not dev[2].discover_peer(addr1, timeout=10):
51         if not dev[2].discover_peer(addr1, timeout=10):
52             if not dev[2].discover_peer(addr1, timeout=10):
53                 raise Exception("Could not discover group client")
54
55     peer = dev[2].get_peer(addr1)
56     if int(peer['dev_capab'], 16) & 0x02 != 0:
57         raise Exception("Discoverability dev_capab reported: " + peer['dev_capab'])
58     dev[2].p2p_stop_find()
59
60     if "OK" not in dev[1].request("P2P_SET discoverability 1"):
61         raise Exception("P2P_SET discoverability 1 failed")
62     dev[1].dump_monitor()
63     dev[1].group_request("REASSOCIATE")
64     ev = dev[1].wait_group_event(["CTRL-EVENT-CONNECTED"], timeout=20)
65     if ev is None:
66         raise Exception("Connection timed out")
67
68     dev[2].request("P2P_FLUSH")
69     if not dev[2].discover_peer(addr1, timeout=10):
70         if not dev[2].discover_peer(addr1, timeout=10):
71             if not dev[2].discover_peer(addr1, timeout=10):
72                 raise Exception("Could not discover group client")
73
74     peer = dev[2].get_peer(addr1)
75     if int(peer['dev_capab'], 16) & 0x02 != 0x02:
76         raise Exception("Discoverability dev_capab reported: " + peer['dev_capab'])
77     dev[2].p2p_stop_find()
78
79 def test_p2p_set_managed(dev):
80     """P2P_SET managed"""
81     addr0 = dev[0].p2p_dev_addr()
82
83     if "OK" not in dev[0].request("P2P_SET managed 1"):
84         raise Exception("P2P_SET managed 1 failed")
85
86     dev[0].p2p_listen()
87     if not dev[1].discover_peer(addr0):
88         raise Exception("Could not discover peer")
89     peer = dev[1].get_peer(addr0)
90     if int(peer['dev_capab'], 16) & 0x08 != 0x08:
91         raise Exception("Managed dev_capab not reported: " + peer['dev_capab'])
92     dev[1].p2p_stop_find()
93
94     if "OK" not in dev[0].request("P2P_SET managed 0"):
95         raise Exception("P2P_SET managed 0 failed")
96
97     if not dev[2].discover_peer(addr0):
98         raise Exception("Could not discover peer")
99     peer = dev[2].get_peer(addr0)
100     if int(peer['dev_capab'], 16) & 0x08 != 0:
101         raise Exception("Managed dev_capab reported: " + peer['dev_capab'])
102     dev[2].p2p_stop_find()
103     dev[0].p2p_stop_find()
104
105 def test_p2p_set_ssid_postfix(dev):
106     """P2P_SET ssid_postfix"""
107     addr0 = dev[0].p2p_dev_addr()
108     addr1 = dev[1].p2p_dev_addr()
109     postfix = "12345678901234567890123"
110
111     try:
112         if "OK" not in dev[0].request("P2P_SET ssid_postfix " + postfix):
113             raise Exception("P2P_SET ssid_postfix failed")
114         dev[0].p2p_start_go(freq="2412")
115         pin = dev[1].wps_read_pin()
116         dev[0].p2p_go_authorize_client(pin)
117         dev[1].p2p_connect_group(addr0, pin, timeout=20, social=True, freq="2412")
118         if postfix not in dev[1].get_group_status_field("ssid"):
119             raise Exception("SSID postfix missing from status")
120         if postfix not in dev[1].group_request("SCAN_RESULTS"):
121             raise Exception("SSID postfix missing from scan results")
122     finally:
123         dev[0].request("P2P_SET ssid_postfix ")