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