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