1 # P2P group formation test cases
2 # Copyright (c) 2013-2019, 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 logger
= logging
.getLogger()
18 from utils
import HwsimSkip
19 from wpasupplicant
import WpaSupplicant
20 from p2p_utils
import *
21 from test_p2p_messages
import parse_p2p_public_action
, p2p_hdr
, p2p_attr_capability
, p2p_attr_go_intent
, p2p_attr_config_timeout
, p2p_attr_listen_channel
, p2p_attr_intended_interface_addr
, p2p_attr_channel_list
, p2p_attr_device_info
, p2p_attr_operating_channel
, ie_p2p
, ie_wsc
, mgmt_tx
, P2P_GO_NEG_REQ
24 def test_grpform(dev
):
25 """P2P group formation using PIN and authorized connection (init -> GO)"""
27 dev
[0].global_request("SET p2p_group_idle 2")
28 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
29 r_dev
=dev
[1], r_intent
=0)
30 check_grpform_results(i_res
, r_res
)
32 ev
= dev
[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout
=10)
34 raise Exception("GO did not remove group on idle timeout")
35 if "GO reason=IDLE" not in ev
:
36 raise Exception("Unexpected group removal event: " + ev
)
38 dev
[0].global_request("SET p2p_group_idle 0")
40 def test_grpform_a(dev
):
41 """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)"""
42 dev
[0].global_request("SET p2p_no_group_iface 0")
43 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
44 r_dev
=dev
[1], r_intent
=0)
45 if "p2p-wlan" not in i_res
['ifname']:
46 raise Exception("Unexpected group interface name")
47 check_grpform_results(i_res
, r_res
)
48 remove_group(dev
[0], dev
[1])
49 if i_res
['ifname'] in utils
.get_ifnames():
50 raise Exception("Group interface netdev was not removed")
52 def test_grpform_b(dev
):
53 """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)"""
54 dev
[1].global_request("SET p2p_no_group_iface 0")
55 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
56 r_dev
=dev
[1], r_intent
=0)
57 if "p2p-wlan" not in r_res
['ifname']:
58 raise Exception("Unexpected group interface name")
59 check_grpform_results(i_res
, r_res
)
60 addr
= dev
[0].group_request("P2P_GROUP_MEMBER " + dev
[1].p2p_dev_addr())
62 raise Exception("P2P_GROUP_MEMBER failed")
63 if addr
!= dev
[1].p2p_interface_addr():
64 raise Exception("Unexpected P2P_GROUP_MEMBER result: " + addr
)
65 if "FAIL" not in dev
[0].group_request("P2P_GROUP_MEMBER a"):
66 raise Exception("Invalid P2P_GROUP_MEMBER command accepted")
67 if "FAIL" not in dev
[0].group_request("P2P_GROUP_MEMBER 00:11:22:33:44:55"):
68 raise Exception("P2P_GROUP_MEMBER for non-member accepted")
69 remove_group(dev
[0], dev
[1])
70 if r_res
['ifname'] in utils
.get_ifnames():
71 raise Exception("Group interface netdev was not removed")
73 def test_grpform_c(dev
):
74 """P2P group formation using PIN and authorized connection (init -> GO) (group iface)"""
75 dev
[0].global_request("SET p2p_no_group_iface 0")
76 dev
[1].global_request("SET p2p_no_group_iface 0")
77 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
78 r_dev
=dev
[1], r_intent
=0)
79 if "p2p-wlan" not in i_res
['ifname']:
80 raise Exception("Unexpected group interface name")
81 if "p2p-wlan" not in r_res
['ifname']:
82 raise Exception("Unexpected group interface name")
83 check_grpform_results(i_res
, r_res
)
84 remove_group(dev
[0], dev
[1])
85 if i_res
['ifname'] in utils
.get_ifnames():
86 raise Exception("Group interface netdev was not removed")
87 if r_res
['ifname'] in utils
.get_ifnames():
88 raise Exception("Group interface netdev was not removed")
91 def test_grpform2(dev
):
92 """P2P group formation using PIN and authorized connection (resp -> GO)"""
93 go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0, r_dev
=dev
[1], r_intent
=15)
94 remove_group(dev
[0], dev
[1])
96 def test_grpform2_c(dev
):
97 """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)"""
98 dev
[0].global_request("SET p2p_no_group_iface 0")
99 dev
[1].global_request("SET p2p_no_group_iface 0")
100 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0, r_dev
=dev
[1], r_intent
=15)
101 remove_group(dev
[0], dev
[1])
102 if i_res
['ifname'] in utils
.get_ifnames():
103 raise Exception("Group interface netdev was not removed")
104 if r_res
['ifname'] in utils
.get_ifnames():
105 raise Exception("Group interface netdev was not removed")
108 def test_grpform3(dev
):
109 """P2P group formation using PIN and re-init GO Negotiation"""
110 go_neg_pin(i_dev
=dev
[0], i_intent
=15, r_dev
=dev
[1], r_intent
=0)
111 remove_group(dev
[0], dev
[1])
113 def test_grpform3_c(dev
):
114 """P2P group formation using PIN and re-init GO Negotiation (group iface)"""
115 dev
[0].global_request("SET p2p_no_group_iface 0")
116 dev
[1].global_request("SET p2p_no_group_iface 0")
117 [i_res
, r_res
] = go_neg_pin(i_dev
=dev
[0], i_intent
=15, r_dev
=dev
[1], r_intent
=0)
118 remove_group(dev
[0], dev
[1])
119 if i_res
['ifname'] in utils
.get_ifnames():
120 raise Exception("Group interface netdev was not removed")
121 if r_res
['ifname'] in utils
.get_ifnames():
122 raise Exception("Group interface netdev was not removed")
125 def test_grpform4(dev
):
126 """P2P group formation response during p2p_find"""
127 addr1
= dev
[1].p2p_dev_addr()
129 dev
[0].discover_peer(addr1
)
130 dev
[1].p2p_find(social
=True)
132 dev
[0].global_request("P2P_CONNECT " + addr1
+ " 12345670 display")
133 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=15)
135 raise Exception("GO Negotiation RX timed out")
137 dev
[1].p2p_stop_find()
138 dev
[0].p2p_stop_find()
141 def test_grpform_pbc(dev
):
142 """P2P group formation using PBC and re-init GO Negotiation"""
143 [i_res
, r_res
] = go_neg_pbc(i_dev
=dev
[0], i_intent
=15, r_dev
=dev
[1], r_intent
=0)
144 check_grpform_results(i_res
, r_res
)
145 if i_res
['role'] != 'GO' or r_res
['role'] != 'client':
146 raise Exception("Unexpected device roles")
147 remove_group(dev
[0], dev
[1])
150 def test_grpform_pd(dev
):
151 """P2P group formation with PD-before-GO-Neg workaround"""
152 [i_res
, r_res
] = go_neg_pbc(i_dev
=dev
[0], provdisc
=True, r_dev
=dev
[1], r_listen
=True)
153 check_grpform_results(i_res
, r_res
)
154 remove_group(dev
[0], dev
[1])
156 def test_grpform_ext_listen(dev
):
157 """P2P group formation with extended listen timing enabled"""
158 addr0
= dev
[0].p2p_dev_addr()
160 if "FAIL" not in dev
[0].global_request("P2P_EXT_LISTEN 100"):
161 raise Exception("Invalid P2P_EXT_LISTEN accepted")
162 if "OK" not in dev
[0].global_request("P2P_EXT_LISTEN 300 1000"):
163 raise Exception("Failed to set extended listen timing")
164 if "OK" not in dev
[1].global_request("P2P_EXT_LISTEN 200 40000"):
165 raise Exception("Failed to set extended listen timing")
166 [i_res
, r_res
] = go_neg_pbc(i_dev
=dev
[0], provdisc
=True, r_dev
=dev
[1],
167 r_listen
=True, i_freq
="2417", r_freq
="2417",
168 i_intent
=1, r_intent
=15)
169 check_grpform_results(i_res
, r_res
)
170 peer1
= dev
[0].get_peer(dev
[1].p2p_dev_addr())
171 if peer1
['ext_listen_interval'] != "40000":
172 raise Exception("Extended listen interval not discovered correctly")
173 if peer1
['ext_listen_period'] != "200":
174 raise Exception("Extended listen period not discovered correctly")
175 peer0
= dev
[1].get_peer(dev
[0].p2p_dev_addr())
176 if peer0
['ext_listen_interval'] != "1000":
177 raise Exception("Extended listen interval not discovered correctly")
178 if peer0
['ext_listen_period'] != "300":
179 raise Exception("Extended listen period not discovered correctly")
180 if not dev
[2].discover_peer(addr0
):
181 raise Exception("Could not discover peer during ext listen")
182 remove_group(dev
[0], dev
[1])
184 if "OK" not in dev
[0].global_request("P2P_EXT_LISTEN"):
185 raise Exception("Failed to clear extended listen timing")
186 if "OK" not in dev
[1].global_request("P2P_EXT_LISTEN"):
187 raise Exception("Failed to clear extended listen timing")
189 def test_grpform_ext_listen_oper(dev
):
190 """P2P extended listen timing operations"""
192 _test_grpform_ext_listen_oper(dev
)
194 dev
[0].global_request("P2P_EXT_LISTEN")
196 def _test_grpform_ext_listen_oper(dev
):
197 addr0
= dev
[0].p2p_dev_addr()
198 dev
[0].global_request("SET p2p_no_group_iface 0")
199 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
200 wpas
.interface_add("wlan5")
201 addr1
= wpas
.p2p_dev_addr()
202 wpas
.request("P2P_SET listen_channel 1")
203 wpas
.global_request("SET p2p_no_group_iface 0")
204 wpas
.request("P2P_LISTEN")
205 if not dev
[0].discover_peer(addr1
):
206 raise Exception("Could not discover peer")
207 dev
[0].request("P2P_LISTEN")
208 if not wpas
.discover_peer(addr0
):
209 raise Exception("Could not discover peer (2)")
211 dev
[0].global_request("P2P_EXT_LISTEN 300 500")
212 dev
[0].global_request("P2P_CONNECT " + addr1
+ " 12345670 display auth go_intent=0 freq=2417")
213 wpas
.global_request("P2P_CONNECT " + addr0
+ " 12345670 enter go_intent=15 freq=2417")
214 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=15)
216 raise Exception("GO Negotiation failed")
217 ifaces
= wpas
.request("INTERFACES").splitlines()
218 iface
= ifaces
[0] if "p2p-wlan" in ifaces
[0] else ifaces
[1]
219 wpas
.group_ifname
= iface
220 if "OK" not in wpas
.group_request("STOP_AP"):
221 raise Exception("STOP_AP failed")
222 wpas
.group_request("SET ext_mgmt_frame_handling 1")
223 dev
[1].p2p_find(social
=True)
225 if dev
[1].peer_known(addr0
):
226 raise Exception("Unexpected peer discovery")
227 ifaces
= dev
[0].request("INTERFACES").splitlines()
228 iface
= ifaces
[0] if "p2p-wlan" in ifaces
[0] else ifaces
[1]
229 if "OK" not in dev
[0].global_request("P2P_GROUP_REMOVE " + iface
):
230 raise Exception("Failed to request group removal")
236 while count
< timeout
* 4:
239 if dev
[1].peer_known(addr0
):
242 dev
[1].p2p_stop_find()
244 raise Exception("Could not discover peer that was supposed to use extended listen")
247 def test_both_go_intent_15(dev
):
248 """P2P GO Negotiation with both devices using GO intent 15"""
249 go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15, r_dev
=dev
[1], r_intent
=15, expect_failure
=True, i_go_neg_status
=9)
252 def test_both_go_neg_display(dev
):
253 """P2P GO Negotiation with both devices trying to display PIN"""
254 go_neg_pin_authorized(i_dev
=dev
[0], r_dev
=dev
[1], expect_failure
=True, i_go_neg_status
=10, i_method
='display', r_method
='display')
257 def test_both_go_neg_enter(dev
):
258 """P2P GO Negotiation with both devices trying to enter PIN"""
259 go_neg_pin_authorized(i_dev
=dev
[0], r_dev
=dev
[1], expect_failure
=True, i_go_neg_status
=10, i_method
='enter', r_method
='enter')
262 def test_go_neg_pbc_vs_pin(dev
):
263 """P2P GO Negotiation with one device using PBC and the other PIN"""
264 addr0
= dev
[0].p2p_dev_addr()
265 addr1
= dev
[1].p2p_dev_addr()
267 if not dev
[0].discover_peer(addr1
):
268 raise Exception("Could not discover peer")
270 if "OK" not in dev
[0].request("P2P_CONNECT " + addr1
+ " pbc auth"):
271 raise Exception("Failed to authorize GO Neg")
272 if not dev
[1].discover_peer(addr0
):
273 raise Exception("Could not discover peer")
274 if "OK" not in dev
[1].request("P2P_CONNECT " + addr0
+ " 12345670 display"):
275 raise Exception("Failed to initiate GO Neg")
276 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=10)
278 raise Exception("GO Negotiation failure timed out")
279 if "status=10" not in ev
:
280 raise Exception("Unexpected failure reason: " + ev
)
283 def test_go_neg_pin_vs_pbc(dev
):
284 """P2P GO Negotiation with one device using PIN and the other PBC"""
285 addr0
= dev
[0].p2p_dev_addr()
286 addr1
= dev
[1].p2p_dev_addr()
288 if not dev
[0].discover_peer(addr1
):
289 raise Exception("Could not discover peer")
291 if "OK" not in dev
[0].request("P2P_CONNECT " + addr1
+ " 12345670 display auth"):
292 raise Exception("Failed to authorize GO Neg")
293 if not dev
[1].discover_peer(addr0
):
294 raise Exception("Could not discover peer")
295 if "OK" not in dev
[1].request("P2P_CONNECT " + addr0
+ " pbc"):
296 raise Exception("Failed to initiate GO Neg")
297 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=10)
299 raise Exception("GO Negotiation failure timed out")
300 if "status=10" not in ev
:
301 raise Exception("Unexpected failure reason: " + ev
)
303 def test_grpform_per_sta_psk(dev
):
304 """P2P group formation with per-STA PSKs"""
305 dev
[0].global_request("P2P_SET per_sta_psk 1")
306 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15, r_dev
=dev
[1], r_intent
=0)
307 check_grpform_results(i_res
, r_res
)
309 pin
= dev
[2].wps_read_pin()
310 dev
[0].p2p_go_authorize_client(pin
)
311 c_res
= dev
[2].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
312 check_grpform_results(i_res
, c_res
)
314 if r_res
['psk'] == c_res
['psk']:
315 raise Exception("Same PSK assigned for both clients")
317 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
319 dev
[0].remove_group()
320 dev
[1].wait_go_ending_session()
321 dev
[2].wait_go_ending_session()
323 def test_grpform_per_sta_psk_wps(dev
):
324 """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
325 dev
[0].global_request("P2P_SET per_sta_psk 1")
326 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15, r_dev
=dev
[1], r_intent
=0)
327 check_grpform_results(i_res
, r_res
)
329 dev
[0].p2p_go_authorize_client_pbc()
330 dev
[2].request("WPS_PBC")
331 dev
[2].wait_connected(timeout
=30)
333 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
335 dev
[0].remove_group()
336 dev
[2].request("DISCONNECT")
337 dev
[1].wait_go_ending_session()
340 def test_grpform_force_chan_go(dev
):
341 """P2P group formation forced channel selection by GO"""
342 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
344 r_dev
=dev
[1], r_intent
=0,
346 check_grpform_results(i_res
, r_res
)
347 if i_res
['freq'] != "2432":
348 raise Exception("Unexpected channel - did not follow GO's forced channel")
349 remove_group(dev
[0], dev
[1])
352 def test_grpform_force_chan_cli(dev
):
353 """P2P group formation forced channel selection by client"""
354 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0,
356 r_dev
=dev
[1], r_intent
=15,
358 check_grpform_results(i_res
, r_res
)
359 if i_res
['freq'] != "2417":
360 raise Exception("Unexpected channel - did not follow GO's forced channel")
361 remove_group(dev
[0], dev
[1])
364 def test_grpform_force_chan_conflict(dev
):
365 """P2P group formation fails due to forced channel mismatch"""
366 go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0, i_freq
=2422,
367 r_dev
=dev
[1], r_intent
=15, r_freq
=2427,
368 expect_failure
=True, i_go_neg_status
=7)
371 def test_grpform_pref_chan_go(dev
):
372 """P2P group formation preferred channel selection by GO"""
374 dev
[0].request("SET p2p_pref_chan 81:7")
375 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
376 r_dev
=dev
[1], r_intent
=0,
378 check_grpform_results(i_res
, r_res
)
379 if i_res
['freq'] != "2442":
380 raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
381 remove_group(dev
[0], dev
[1])
383 dev
[0].request("SET p2p_pref_chan ")
386 def test_grpform_pref_chan_go_overridden(dev
):
387 """P2P group formation preferred channel selection by GO overridden by client"""
389 dev
[1].request("SET p2p_pref_chan 81:7")
390 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0,
392 r_dev
=dev
[1], r_intent
=15,
394 check_grpform_results(i_res
, r_res
)
395 if i_res
['freq'] != "2422":
396 raise Exception("Unexpected channel - did not follow client's forced channel")
397 remove_group(dev
[0], dev
[1])
399 dev
[1].request("SET p2p_pref_chan ")
402 def test_grpform_no_go_freq_forcing_chan(dev
):
403 """P2P group formation with no-GO freq forcing channel"""
405 dev
[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
406 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0,
407 r_dev
=dev
[1], r_intent
=15,
409 check_grpform_results(i_res
, r_res
)
410 if int(i_res
['freq']) > 4000:
411 raise Exception("Unexpected channel - did not follow no-GO freq")
412 remove_group(dev
[0], dev
[1])
414 dev
[1].request("SET p2p_no_go_freq ")
417 def test_grpform_no_go_freq_conflict(dev
):
418 """P2P group formation fails due to no-GO range forced by client"""
420 dev
[1].request("SET p2p_no_go_freq 2000-3000")
421 go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0, i_freq
=2422,
422 r_dev
=dev
[1], r_intent
=15,
423 expect_failure
=True, i_go_neg_status
=7)
425 dev
[1].request("SET p2p_no_go_freq ")
428 def test_grpform_no_5ghz_world_roaming(dev
):
429 """P2P group formation with world roaming regulatory"""
430 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0,
431 r_dev
=dev
[1], r_intent
=15,
433 check_grpform_results(i_res
, r_res
)
434 if int(i_res
['freq']) > 4000:
435 raise Exception("Unexpected channel - did not follow world roaming rules")
436 remove_group(dev
[0], dev
[1])
439 def test_grpform_no_5ghz_add_cli(dev
):
440 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
442 dev
[0].request("SET p2p_add_cli_chan 1")
443 dev
[1].request("SET p2p_add_cli_chan 1")
444 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0,
445 r_dev
=dev
[1], r_intent
=14,
447 check_grpform_results(i_res
, r_res
)
448 if int(i_res
['freq']) > 4000:
449 raise Exception("Unexpected channel - did not follow world roaming rules")
450 remove_group(dev
[0], dev
[1])
452 dev
[0].request("SET p2p_add_cli_chan 0")
453 dev
[1].request("SET p2p_add_cli_chan 0")
456 def test_grpform_no_5ghz_add_cli2(dev
):
457 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
459 dev
[0].request("SET p2p_add_cli_chan 1")
460 dev
[1].request("SET p2p_add_cli_chan 1")
461 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=14,
462 r_dev
=dev
[1], r_intent
=0,
464 check_grpform_results(i_res
, r_res
)
465 if int(i_res
['freq']) > 4000:
466 raise Exception("Unexpected channel - did not follow world roaming rules")
467 remove_group(dev
[0], dev
[1])
469 dev
[0].request("SET p2p_add_cli_chan 0")
470 dev
[1].request("SET p2p_add_cli_chan 0")
473 def test_grpform_no_5ghz_add_cli3(dev
):
474 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
476 dev
[0].request("SET p2p_add_cli_chan 1")
477 dev
[1].request("SET p2p_add_cli_chan 1")
478 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=0,
479 r_dev
=dev
[1], r_intent
=15,
481 check_grpform_results(i_res
, r_res
)
482 if int(i_res
['freq']) > 4000:
483 raise Exception("Unexpected channel - did not follow world roaming rules")
484 remove_group(dev
[0], dev
[1])
486 dev
[0].request("SET p2p_add_cli_chan 0")
487 dev
[1].request("SET p2p_add_cli_chan 0")
490 def test_grpform_no_5ghz_add_cli4(dev
):
491 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
493 dev
[0].request("SET p2p_add_cli_chan 1")
494 dev
[1].request("SET p2p_add_cli_chan 1")
495 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
496 r_dev
=dev
[1], r_intent
=0,
498 check_grpform_results(i_res
, r_res
)
499 if int(i_res
['freq']) > 4000:
500 raise Exception("Unexpected channel - did not follow world roaming rules")
501 remove_group(dev
[0], dev
[1])
503 dev
[0].request("SET p2p_add_cli_chan 0")
504 dev
[1].request("SET p2p_add_cli_chan 0")
507 def test_grpform_incorrect_pin(dev
):
508 """P2P GO Negotiation with incorrect PIN"""
510 addr1
= dev
[1].p2p_dev_addr()
511 if not dev
[0].discover_peer(addr1
):
512 raise Exception("Peer not found")
513 res
= dev
[1].global_request("P2P_CONNECT " + dev
[0].p2p_dev_addr() + " pin auth go_intent=0")
515 raise Exception("P2P_CONNECT failed to generate PIN")
516 logger
.info("PIN from P2P_CONNECT: " + res
)
517 dev
[0].global_request("P2P_CONNECT " + addr1
+ " 00000000 enter go_intent=15")
518 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=15)
520 raise Exception("GO Negotiation did not complete successfully(0)")
521 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=15)
523 raise Exception("GO Negotiation did not complete successfully(1)")
524 ev
= dev
[1].wait_global_event(["WPS-FAIL"], timeout
=15)
526 raise Exception("WPS failure not reported(1)")
527 if "msg=8 config_error=18" not in ev
:
528 raise Exception("Unexpected WPS failure(1): " + ev
)
529 ev
= dev
[0].wait_global_event(["WPS-FAIL"], timeout
=15)
531 raise Exception("WPS failure not reported")
532 if "msg=8 config_error=18" not in ev
:
533 raise Exception("Unexpected WPS failure: " + ev
)
534 ev
= dev
[1].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout
=10)
536 raise Exception("Group formation failure timed out")
537 ev
= dev
[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout
=5)
539 raise Exception("Group formation failure timed out")
542 def test_grpform_reject(dev
):
543 """User rejecting group formation attempt by a P2P peer"""
544 addr0
= dev
[0].p2p_dev_addr()
546 dev
[1].p2p_go_neg_init(addr0
, None, "pbc")
547 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=15)
549 raise Exception("GO Negotiation timed out")
550 if "OK" in dev
[0].global_request("P2P_REJECT foo"):
551 raise Exception("Invalid P2P_REJECT accepted")
552 if "FAIL" in dev
[0].global_request("P2P_REJECT " + ev
.split(' ')[1]):
553 raise Exception("P2P_REJECT failed")
554 dev
[1].request("P2P_STOP_FIND")
555 dev
[1].p2p_go_neg_init(addr0
, None, "pbc")
556 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=10)
558 raise Exception("Rejection not reported")
559 if "status=11" not in ev
:
560 raise Exception("Unexpected status code in rejection")
563 def test_grpform_pd_no_probe_resp(dev
):
564 """GO Negotiation after PD, but no Probe Response"""
565 addr0
= dev
[0].p2p_dev_addr()
566 addr1
= dev
[1].p2p_dev_addr()
568 if not dev
[1].discover_peer(addr0
):
569 raise Exception("Peer not found")
570 dev
[1].p2p_stop_find()
571 dev
[0].p2p_stop_find()
572 peer
= dev
[0].get_peer(addr1
)
573 if peer
['listen_freq'] == '0':
574 raise Exception("Peer listen frequency not learned from Probe Request")
576 dev
[0].request("P2P_FLUSH")
578 dev
[1].global_request("P2P_PROV_DISC " + addr0
+ " display")
579 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=5)
581 raise Exception("PD Request timed out")
582 ev
= dev
[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=5)
584 raise Exception("PD Response timed out")
585 peer
= dev
[0].get_peer(addr1
)
586 if peer
['listen_freq'] != '0':
587 raise Exception("Peer listen frequency learned unexpectedly from PD Request")
589 pin
= dev
[0].wps_read_pin()
590 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " " + pin
+ " enter"):
591 raise Exception("P2P_CONNECT on initiator failed")
592 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=5)
594 raise Exception("GO Negotiation start timed out")
595 peer
= dev
[0].get_peer(addr1
)
596 if peer
['listen_freq'] == '0':
597 raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
598 if "FAIL" in dev
[0].global_request("P2P_CONNECT " + addr1
+ " " + pin
+ " display"):
599 raise Exception("P2P_CONNECT on responder failed")
600 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
602 raise Exception("Group formation timed out")
603 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
605 raise Exception("Group formation timed out")
607 def test_go_neg_two_peers(dev
):
608 """P2P GO Negotiation rejected due to already started negotiation with another peer"""
609 addr0
= dev
[0].p2p_dev_addr()
610 addr1
= dev
[1].p2p_dev_addr()
611 addr2
= dev
[2].p2p_dev_addr()
614 if not dev
[0].discover_peer(addr1
):
615 raise Exception("Could not discover peer")
616 if not dev
[0].discover_peer(addr2
):
617 raise Exception("Could not discover peer")
618 if "OK" not in dev
[0].request("P2P_CONNECT " + addr2
+ " pbc auth"):
619 raise Exception("Failed to authorize GO Neg")
621 if not dev
[2].discover_peer(addr0
):
622 raise Exception("Could not discover peer")
623 if "OK" not in dev
[0].request("P2P_CONNECT " + addr1
+ " pbc"):
624 raise Exception("Failed to initiate GO Neg")
625 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=5)
627 raise Exception("timeout on GO Neg RX event")
628 dev
[2].request("P2P_CONNECT " + addr0
+ " pbc")
629 ev
= dev
[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=10)
631 raise Exception("Rejection not reported")
632 if "status=5" not in ev
:
633 raise Exception("Unexpected status code in rejection: " + ev
)
635 def clear_pbc_overlap(dev
, ap
):
636 hostapd
.remove_bss(ap
)
637 dev
[0].request("P2P_CANCEL")
638 dev
[1].request("P2P_CANCEL")
639 dev
[0].p2p_stop_find()
640 dev
[1].p2p_stop_find()
641 remove_group(dev
[0], dev
[1], allow_failure
=True)
642 dev
[0].dump_monitor()
643 dev
[1].dump_monitor()
645 dev
[0].flush_scan_cache()
646 dev
[1].flush_scan_cache()
650 def test_grpform_pbc_overlap(dev
, apdev
):
651 """P2P group formation during PBC overlap"""
652 params
= {"ssid": "wps", "eap_server": "1", "wps_state": "1"}
653 hapd
= hostapd
.add_ap(apdev
[0], params
)
654 hapd
.request("WPS_PBC")
657 # Since P2P Client scan case is now optimized to use a specific SSID, the
658 # WPS AP will not reply to that and the scan after GO Negotiation can quite
659 # likely miss the AP due to dwell time being short enough to miss the Beacon
660 # frame. This has made the test case somewhat pointless, but keep it here
661 # for now with an additional scan to confirm that PBC detection works if
662 # there is a BSS entry for a overlapping AP.
663 for i
in range(0, 5):
664 dev
[0].scan(freq
="2412")
665 if dev
[0].get_bss(apdev
[0]['bssid']) is not None:
668 addr0
= dev
[0].p2p_dev_addr()
669 addr1
= dev
[1].p2p_dev_addr()
671 if not dev
[1].discover_peer(addr0
):
672 raise Exception("Could not discover peer")
674 if not dev
[0].discover_peer(addr1
):
675 raise Exception("Could not discover peer")
677 if "OK" not in dev
[0].global_request("P2P_CONNECT " + addr1
+ " pbc auth go_intent=0"):
678 raise Exception("Failed to authorize GO Neg")
679 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=15 freq=2412"):
680 raise Exception("Failed to initiate GO Neg")
681 ev
= dev
[0].wait_global_event(["WPS-OVERLAP-DETECTED",
682 "P2P-GROUP-FORMATION-SUCCESS"], timeout
=15)
683 clear_pbc_overlap(dev
, apdev
[0])
684 if ev
is None or "P2P-GROUP-FORMATION-SUCCESS" not in ev
:
685 raise Exception("P2P group formation did not complete")
688 def test_grpform_pbc_overlap_group_iface(dev
, apdev
):
689 """P2P group formation during PBC overlap using group interfaces"""
690 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
691 # update use this information.
692 params
= {"ssid": "wps", "eap_server": "1", "wps_state": "1",
693 "beacon_int": "15", 'manage_p2p': '1'}
694 hapd
= hostapd
.add_ap(apdev
[0], params
)
695 hapd
.request("WPS_PBC")
697 dev
[0].request("SET p2p_no_group_iface 0")
698 dev
[1].request("SET p2p_no_group_iface 0")
700 addr0
= dev
[0].p2p_dev_addr()
701 addr1
= dev
[1].p2p_dev_addr()
703 if not dev
[1].discover_peer(addr0
):
704 raise Exception("Could not discover peer")
706 if not dev
[0].discover_peer(addr1
):
707 raise Exception("Could not discover peer")
708 dev
[0].p2p_stop_find()
709 dev
[0].scan(freq
="2412")
711 if "OK" not in dev
[0].global_request("P2P_CONNECT " + addr1
+ " pbc auth go_intent=0"):
712 raise Exception("Failed to authorize GO Neg")
713 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=15 freq=2412"):
714 raise Exception("Failed to initiate GO Neg")
715 ev
= dev
[0].wait_global_event(["WPS-OVERLAP-DETECTED",
716 "P2P-GROUP-FORMATION-SUCCESS"], timeout
=15)
717 clear_pbc_overlap(dev
, apdev
[0])
718 if ev
is None or "P2P-GROUP-FORMATION-SUCCESS" not in ev
:
719 raise Exception("P2P group formation did not complete")
722 def test_grpform_goneg_fail_with_group_iface(dev
):
723 """P2P group formation fails while using group interface"""
724 dev
[0].request("SET p2p_no_group_iface 0")
726 peer
= dev
[1].p2p_dev_addr()
727 if not dev
[0].discover_peer(peer
):
728 raise Exception("Peer " + peer
+ " not found")
729 if "OK" not in dev
[1].request("P2P_REJECT " + dev
[0].p2p_dev_addr()):
730 raise Exception("P2P_REJECT failed")
731 if "OK" not in dev
[0].request("P2P_CONNECT " + peer
+ " pbc"):
732 raise Exception("P2P_CONNECT failed")
733 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=10)
735 raise Exception("GO Negotiation failure timed out")
737 def test_grpform_cred_ready_timeout(dev
, apdev
, params
):
738 """P2P GO Negotiation wait for credentials to become ready [long]"""
739 if not params
['long']:
740 raise HwsimSkip("Skip test case with long duration due to --long not specified")
743 addr1
= dev
[1].p2p_dev_addr()
744 if not dev
[0].discover_peer(addr1
):
745 raise Exception("Peer " + addr1
+ " not found")
746 if not dev
[2].discover_peer(addr1
):
747 raise Exception("Peer " + addr1
+ " not found(2)")
749 start
= os
.times()[4]
751 cmd
= "P2P_CONNECT " + addr1
+ " 12345670 display"
752 if "OK" not in dev
[0].global_request(cmd
):
753 raise Exception("Failed to initiate GO Neg")
755 if "OK" not in dev
[2].global_request(cmd
):
756 raise Exception("Failed to initiate GO Neg(2)")
758 # First, check with p2p_find
759 ev
= dev
[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=30)
761 raise Exception("Too early GO Negotiation timeout reported(2)")
762 dev
[2].dump_monitor()
763 logger
.info("Starting p2p_find to change state")
766 ev
= dev
[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=10)
769 dev
[2].dump_monitor(global_mon
=False)
771 raise Exception("GO Negotiation failure timed out(2)")
772 dev
[2].dump_monitor()
774 logger
.info("GO Negotiation wait time: {} seconds(2)".format(end
- start
))
775 if end
- start
< 120:
776 raise Exception("Too short GO Negotiation wait time(2): {}".format(end
- start
))
778 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
779 wpas
.interface_add("wlan5")
782 ev
= dev
[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
784 raise Exception("Did not discover new device after GO Negotiation failure")
785 if wpas
.p2p_dev_addr() not in ev
:
786 raise Exception("Unexpected device found: " + ev
)
787 dev
[2].p2p_stop_find()
788 dev
[2].dump_monitor()
793 # Finally, verify without p2p_find
794 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=120)
796 raise Exception("GO Negotiation failure timed out")
798 logger
.info("GO Negotiation wait time: {} seconds".format(end
- start
))
799 if end
- start
< 120:
800 raise Exception("Too short GO Negotiation wait time: {}".format(end
- start
))
802 def test_grpform_no_wsc_done(dev
):
803 """P2P group formation with WSC-Done not sent"""
804 addr0
= dev
[0].p2p_dev_addr()
805 addr1
= dev
[1].p2p_dev_addr()
807 for i
in range(0, 2):
808 dev
[0].request("SET ext_eapol_frame_io 1")
809 dev
[1].request("SET ext_eapol_frame_io 1")
811 dev
[1].p2p_go_neg_auth(addr0
, "12345670", "display", 0)
813 dev
[0].p2p_go_neg_init(addr1
, "12345670", "enter", timeout
=20,
814 go_intent
=15, wait_group
=False)
818 ev
= dev
[0].wait_event(["EAPOL-TX"], timeout
=15)
820 raise Exception("Timeout on EAPOL-TX from GO")
822 mode
= dev
[0].get_status_field("mode")
823 res
= dev
[1].request("EAPOL_RX " + addr0
+ " " + ev
.split(' ')[2])
825 raise Exception("EAPOL_RX failed")
826 ev
= dev
[1].wait_event(["EAPOL-TX"], timeout
=15)
828 raise Exception("Timeout on EAPOL-TX from P2P Client")
829 msg
= ev
.split(' ')[2]
830 if msg
[46:56] == "102200010f":
831 logger
.info("Drop WSC_Done")
832 dev
[0].request("SET ext_eapol_frame_io 0")
833 dev
[1].request("SET ext_eapol_frame_io 0")
834 # Fake EAP-Failure to complete session on the client
836 dev
[1].request("EAPOL_RX " + addr0
+ " 0300000404" + id + "0004")
838 res
= dev
[0].request("EAPOL_RX " + addr1
+ " " + msg
)
840 raise Exception("EAPOL_RX failed")
842 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
844 raise Exception("Group formation timed out on GO")
845 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
847 raise Exception("Group formation timed out on P2P Client")
848 dev
[0].remove_group()
849 dev
[1].wait_go_ending_session()
851 if mode
!= "P2P GO - group formation":
852 raise Exception("Unexpected mode on GO during group formation: " + mode
)
855 def test_grpform_wait_peer(dev
):
856 """P2P group formation wait for peer to become ready"""
857 addr0
= dev
[0].p2p_dev_addr()
858 addr1
= dev
[1].p2p_dev_addr()
860 if not dev
[0].discover_peer(addr1
):
861 raise Exception("Peer " + addr1
+ " not found")
862 dev
[0].request("SET extra_roc_dur 500")
863 if "OK" not in dev
[0].request("P2P_CONNECT " + addr1
+ " 12345670 display go_intent=15"):
864 raise Exception("Failed to initiate GO Neg")
866 dev
[1].request("P2P_CONNECT " + addr0
+ " 12345670 enter go_intent=0")
868 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
870 raise Exception("Group formation timed out")
871 dev
[0].group_form_result(ev
)
873 dev
[0].request("SET extra_roc_dur 0")
874 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
876 raise Exception("Group formation timed out")
877 dev
[0].remove_group()
880 def test_invalid_p2p_connect_command(dev
):
881 """P2P_CONNECT error cases"""
882 id = dev
[0].add_network()
885 "00:11:22:33:44:55 pbc persistent=123",
886 "00:11:22:33:44:55 pbc persistent=%d" % id,
887 "00:11:22:33:44:55 pbc go_intent=-1",
888 "00:11:22:33:44:55 pbc go_intent=16",
889 "00:11:22:33:44:55 pin",
890 "00:11:22:33:44:55 pbc freq=0"]:
891 if "FAIL" not in dev
[0].request("P2P_CONNECT " + cmd
):
892 raise Exception("Invalid P2P_CONNECT command accepted: " + cmd
)
894 if "FAIL-INVALID-PIN" not in dev
[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
895 raise Exception("Invalid PIN was not rejected")
896 if "FAIL-INVALID-PIN" not in dev
[0].request("P2P_CONNECT 00:11:22:33:44:55 12345678a"):
897 raise Exception("Invalid PIN was not rejected")
899 if "FAIL-CHANNEL-UNSUPPORTED" not in dev
[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
900 raise Exception("Unsupported channel not reported")
903 def test_p2p_unauthorize(dev
):
904 """P2P_UNAUTHORIZE to unauthorize a peer"""
905 if "FAIL" not in dev
[0].request("P2P_UNAUTHORIZE foo"):
906 raise Exception("Invalid P2P_UNAUTHORIZE accepted")
907 if "FAIL" not in dev
[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
908 raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
910 addr0
= dev
[0].p2p_dev_addr()
911 addr1
= dev
[1].p2p_dev_addr()
913 pin
= dev
[0].wps_read_pin()
914 dev
[0].p2p_go_neg_auth(addr1
, pin
, "display")
916 if "OK" not in dev
[0].request("P2P_UNAUTHORIZE " + addr1
):
917 raise Exception("P2P_UNAUTHORIZE failed")
918 dev
[1].p2p_go_neg_init(addr0
, pin
, "keypad", timeout
=0)
919 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
921 raise Exception("No GO Negotiation Request RX reported")
924 def test_grpform_pbc_multiple(dev
):
925 """P2P group formation using PBC multiple times in a row"""
927 dev
[1].request("SET passive_scan 1")
929 [i_res
, r_res
] = go_neg_pbc_authorized(i_dev
=dev
[0], i_intent
=15,
930 r_dev
=dev
[1], r_intent
=0)
931 remove_group(dev
[0], dev
[1])
933 dev
[1].request("SET passive_scan 0")
934 dev
[1].flush_scan_cache()
936 def test_grpform_not_ready(dev
):
937 """Not ready for GO Negotiation (listen)"""
938 addr0
= dev
[0].p2p_dev_addr()
939 addr2
= dev
[2].p2p_dev_addr()
941 if not dev
[1].discover_peer(addr0
):
942 raise Exception("Could not discover peer")
943 dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc")
944 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=5)
946 raise Exception("No P2P-GO-NEG-REQUEST event")
947 dev
[0].dump_monitor()
949 if not dev
[2].discover_peer(addr0
):
950 raise Exception("Could not discover peer(2)")
952 dev
[i
].p2p_stop_find()
954 def test_grpform_not_ready2(dev
):
955 """Not ready for GO Negotiation (search)"""
956 addr0
= dev
[0].p2p_dev_addr()
957 addr2
= dev
[2].p2p_dev_addr()
958 dev
[0].p2p_find(social
=True)
959 if not dev
[1].discover_peer(addr0
):
960 raise Exception("Could not discover peer")
961 dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc")
962 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=5)
964 raise Exception("No P2P-GO-NEG-REQUEST event")
965 dev
[0].dump_monitor()
968 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
970 raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
972 raise Exception("Unexpected peer discovered: " + ev
)
974 dev
[i
].p2p_stop_find()
977 def test_grpform_and_scan(dev
):
978 """GO Negotiation and scan operations"""
979 addr0
= dev
[0].p2p_dev_addr()
980 addr1
= dev
[1].p2p_dev_addr()
982 if not dev
[0].discover_peer(addr1
):
983 raise Exception("Could not discover peer")
984 dev
[0].p2p_stop_find()
985 dev
[1].p2p_stop_find()
987 if "OK" not in dev
[0].request("SCAN TYPE=ONLY freq=2412-2472"):
988 raise Exception("Could not start scan")
989 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=5)
991 raise Exception("Scan did not start")
993 # Request PD while the previously started scan is still in progress
994 if "OK" not in dev
[0].request("P2P_PROV_DISC %s pbc" % addr1
):
995 raise Exception("Could not request PD")
996 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=10)
998 raise Exception("Scan did not complete")
1002 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP"], timeout
=5)
1004 raise Exception("PD Response not received")
1006 if "OK" not in dev
[0].request("SCAN TYPE=ONLY freq=2412-2472"):
1007 raise Exception("Could not start scan")
1008 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=5)
1010 raise Exception("Scan did not start")
1012 # Request GO Neg while the previously started scan is still in progress
1013 if "OK" not in dev
[0].request("P2P_CONNECT %s pbc" % addr1
):
1014 raise Exception("Could not request GO Negotiation")
1015 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=10)
1017 raise Exception("Scan did not complete")
1019 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
1021 raise Exception("GO Neg Req RX not reported")
1023 dev
[1].p2p_stop_find()
1025 if "OK" not in dev
[1].request("SCAN TYPE=ONLY freq=2412-2472"):
1026 raise Exception("Could not start scan")
1027 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=5)
1029 raise Exception("Scan did not start")
1031 dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc")
1032 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=10)
1034 raise Exception("Scan did not complete")
1036 ev0
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
1038 raise Exception("Group formation timed out on dev0")
1039 dev
[0].group_form_result(ev0
)
1041 ev1
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
1043 raise Exception("Group formation timed out on dev1")
1044 dev
[1].group_form_result(ev1
)
1046 dev
[0].dump_monitor()
1047 dev
[1].dump_monitor()
1049 remove_group(dev
[0], dev
[1])
1051 dev
[0].dump_monitor()
1052 dev
[1].dump_monitor()
1054 def test_grpform_go_neg_dup_on_restart(dev
):
1055 """Duplicated GO Negotiation Request after GO Neg restart"""
1056 if dev
[0].p2p_dev_addr() > dev
[1].p2p_dev_addr():
1062 addr_low
= lower
.p2p_dev_addr()
1063 addr_high
= higher
.p2p_dev_addr()
1065 if not lower
.discover_peer(addr_high
):
1066 raise Exception("Could not discover peer")
1067 lower
.p2p_stop_find()
1069 if "OK" not in lower
.request("P2P_CONNECT %s pbc" % addr_high
):
1070 raise Exception("Could not request GO Negotiation")
1071 ev
= higher
.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
1073 raise Exception("GO Neg Req RX not reported")
1075 # Wait for GO Negotiation Response (Status=1) to go through
1078 if "FAIL" in lower
.request("SET ext_mgmt_frame_handling 1"):
1079 raise Exception("Failed to enable external management frame handling")
1081 higher
.p2p_stop_find()
1082 higher
.global_request("P2P_CONNECT " + addr_low
+ " pbc")
1084 # Wait for the GO Negotiation Request frame of the restarted GO Negotiation
1085 rx_msg
= lower
.mgmt_rx()
1087 raise Exception("MGMT-RX timeout")
1088 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1090 raise Exception("Not a P2P Public Action frame")
1091 if p2p
['subtype'] != 0:
1092 raise Exception("Unexpected P2P Public Action subtype %d" % p2p
['subtype'])
1094 # Send duplicate GO Negotiation Request from the prior instance of GO
1096 lower
.p2p_stop_find()
1097 peer
= higher
.get_peer(addr_low
)
1099 msg
= p2p_hdr(addr_high
, addr_low
, type=P2P_GO_NEG_REQ
, dialog_token
=123)
1100 attrs
= p2p_attr_capability(dev_capab
=0x25, group_capab
=0x08)
1101 attrs
+= p2p_attr_go_intent(go_intent
=7, tie_breaker
=1)
1102 attrs
+= p2p_attr_config_timeout()
1103 attrs
+= p2p_attr_listen_channel(chan
=(int(peer
['listen_freq']) - 2407) // 5)
1104 attrs
+= p2p_attr_intended_interface_addr(lower
.p2p_dev_addr())
1105 attrs
+= p2p_attr_channel_list()
1106 attrs
+= p2p_attr_device_info(addr_low
, config_methods
=0x80, name
="Device A")
1107 attrs
+= p2p_attr_operating_channel()
1108 wsc_attrs
= struct
.pack(">HHH", 0x1012, 2, 4)
1109 msg
['payload'] += ie_p2p(attrs
) + ie_wsc(wsc_attrs
)
1110 mgmt_tx(lower
, "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr_high
, addr_high
, peer
['listen_freq'], binascii
.hexlify(msg
['payload']).decode()))
1112 # Wait for the GO Negotiation Response frame which would have been sent in
1113 # this case previously, but not anymore after the check for
1114 # dev->go_neg_req_sent and dev->flags & P2P_DEV_PEER_WAITING_RESPONSE.
1115 rx_msg
= lower
.mgmt_rx(timeout
=0.2)
1116 if rx_msg
is not None:
1117 raise Exception("Unexpected management frame")
1119 if "FAIL" in lower
.request("SET ext_mgmt_frame_handling 0"):
1120 raise Exception("Failed to disable external management frame handling")
1123 ev
= lower
.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=10)
1125 raise Exception("GO Negotiation did not succeed on dev0")
1127 ev
= higher
.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=10)
1129 raise Exception("GO Negotiation did not succeed on dev1")
1131 ev0
= lower
.wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
1133 raise Exception("Group formation timed out on dev0")
1134 lower
.group_form_result(ev0
)
1136 ev1
= higher
.wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
1138 raise Exception("Group formation timed out on dev1")
1139 higher
.group_form_result(ev1
)
1141 lower
.dump_monitor()
1142 higher
.dump_monitor()
1144 remove_group(lower
, higher
)
1146 lower
.dump_monitor()
1147 higher
.dump_monitor()
1150 def test_grpform_go_neg_stopped(dev
):
1151 """GO Negotiation stopped after TX start"""
1152 addr0
= dev
[0].p2p_dev_addr()
1154 if not dev
[1].discover_peer(addr0
):
1155 raise Exception("Could not discover peer")
1156 dev
[0].p2p_stop_find()
1157 if "OK" not in dev
[1].request("P2P_CONNECT %s pbc" % addr0
):
1158 raise Exception("Could not request GO Negotiation")
1159 dev
[1].p2p_stop_find()
1161 dev
[0].p2p_find(social
=True)
1162 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=1.2)
1163 dev
[0].p2p_stop_find()
1164 dev
[1].p2p_stop_find()
1166 raise Exception("Did not find peer quickly enough after stopped P2P_CONNECT")
1168 def test_grpform_random_addr(dev
):
1169 """P2P group formation with random interface addresses"""
1170 dev
[0].global_request("SET p2p_no_group_iface 0")
1171 dev
[1].global_request("SET p2p_no_group_iface 0")
1173 if "OK" not in dev
[0].global_request("SET p2p_interface_random_mac_addr 1"):
1174 raise Exception("Failed to set p2p_interface_random_mac_addr")
1175 if "OK" not in dev
[1].global_request("SET p2p_interface_random_mac_addr 1"):
1176 raise Exception("Failed to set p2p_interface_random_mac_addr")
1177 [i_res
, r_res
] = go_neg_pin_authorized(i_dev
=dev
[0], i_intent
=15,
1178 r_dev
=dev
[1], r_intent
=0)
1179 if "p2p-wlan" not in i_res
['ifname']:
1180 raise Exception("Unexpected group interface name")
1181 check_grpform_results(i_res
, r_res
)
1182 hwsim_utils
.test_connectivity_p2p(dev
[0], dev
[1])
1183 remove_group(dev
[0], dev
[1])
1184 if i_res
['ifname'] in utils
.get_ifnames():
1185 raise Exception("Group interface netdev was not removed")
1187 dev
[0].global_request("SET p2p_interface_random_mac_addr 0")
1188 dev
[1].global_request("SET p2p_interface_random_mac_addr 0")