2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
7 from remotehost import remote_compatible
10 """P2P_SET commands"""
36 "ssid_postfix 123456789012345678901234" ]:
37 if "FAIL" not in dev[0].request("P2P_SET " + cmd):
38 raise Exception("Invalid P2P_SET accepted: " + cmd)
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()
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")
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")
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()
62 if "OK" not in dev[1].request("P2P_SET discoverability 1"):
63 raise Exception("P2P_SET discoverability 1 failed")
65 dev[1].group_request("REASSOCIATE")
66 ev = dev[1].wait_group_event(["CTRL-EVENT-CONNECTED"], timeout=20)
68 raise Exception("Connection timed out")
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")
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()
81 def test_p2p_set_managed(dev):
83 addr0 = dev[0].p2p_dev_addr()
85 if "OK" not in dev[0].request("P2P_SET managed 1"):
86 raise Exception("P2P_SET managed 1 failed")
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()
96 if "OK" not in dev[0].request("P2P_SET managed 0"):
97 raise Exception("P2P_SET managed 0 failed")
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()
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"
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")
126 dev[0].request("P2P_SET ssid_postfix ")