]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2ps.py
c684662631487344ab9f31c05f661635320396b7
[thirdparty/hostap.git] / tests / hwsim / test_p2ps.py
1 # P2P services
2 # Copyright (c) 2014-2015, Qualcomm Atheros, Inc.
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import logging
8 logger = logging.getLogger()
9 import time
10 import random
11 import re
12
13 import hwsim_utils
14 from wpasupplicant import WpaSupplicant
15 import hostapd
16 from p2p_utils import *
17 from utils import HwsimSkip
18 from hwsim import HWSimRadio
19
20 # Dev[0] -> Advertiser
21 # Dev[1] -> Seeker
22 # ev0 -> Event generated at advertiser side
23 # ev1 -> Event generated at Seeker side
24
25 def p2ps_advertise(r_dev, r_role, svc_name, srv_info, rsp_info=None, cpt=None):
26 """P2PS Advertise function"""
27 adv_id = random.randrange(1, 0xFFFFFFFF)
28 advid = hex(adv_id)[2:]
29
30 cpt_param = (" cpt=" + cpt) if cpt is not None else ""
31
32 if rsp_info is not None and srv_info is not None:
33 if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(advid) + " 1 1108 " + svc_name + cpt_param + " svc_info='" + srv_info + "'" + " rsp_info=" + rsp_info + "'"):
34 raise Exception("P2P_SERVICE_ADD with response info and service info failed")
35
36 if rsp_info is None and srv_info is not None:
37 if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(advid) + " 1 1108 " + svc_name + cpt_param + " svc_info='" + srv_info + "'"):
38 raise Exception("P2P_SERVICE_ADD with service info failed")
39
40 if rsp_info is None and srv_info is None:
41 if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(advid) + " 1 1108 " + svc_name + cpt_param):
42 raise Exception("P2P_SERVICE_ADD without service info and without response info failed")
43
44 if rsp_info is not None and srv_info is None:
45 if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(adv_id) + " 1 1108 " + svc_name + cpt_param + " svc_info='" + " rsp_info=" + rsp_info + "'"):
46 raise Exception("P2P_SERVICE_ADD with response info failed")
47
48 r_dev.p2p_listen()
49 return advid
50
51 def p2ps_exact_seek(i_dev, r_dev, svc_name, srv_info=None,
52 single_peer_expected=True):
53 """P2PS exact service seek request"""
54 if srv_info is not None:
55 ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '" + srv_info + "'")
56 if ev1 is None:
57 raise Exception("Failed to add Service Discovery request for exact seek request")
58
59 if "OK" not in i_dev.global_request("P2P_FIND 10 type=social seek=" + svc_name):
60 raise Exception("Failed to initiate seek operation")
61
62 timeout = time.time() + 10
63 ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
64 while ev1 is not None and not single_peer_expected:
65 if r_dev.p2p_dev_addr() in ev1 and "adv_id=" in ev1:
66 break
67 ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
68
69 if timeout < time.time():
70 raise Exception("Device not found")
71
72 if ev1 is None:
73 raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
74 if r_dev.p2p_dev_addr() not in ev1:
75 raise Exception("Unexpected peer")
76
77 if srv_info is None:
78 adv_id = ev1.split("adv_id=")[1].split(" ")[0]
79 rcvd_svc_name = ev1.split("asp_svc=")[1].split(" ")[0]
80 if rcvd_svc_name != svc_name:
81 raise Exception("service name not matching")
82 else:
83 ev1 = i_dev.wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
84 if ev1 is None:
85 raise Exception("Failed to receive Service Discovery Response")
86 if r_dev.p2p_dev_addr() not in ev1:
87 raise Exception("Service Discovery response from Unknown Peer")
88 if srv_info is not None and srv_info not in ev1:
89 raise Exception("service info not available in Service Discovery response")
90 adv_id = ev1.split(" ")[3]
91 rcvd_svc_name = ev1.split(" ")[6]
92 if rcvd_svc_name != svc_name:
93 raise Exception("service name not matching")
94
95 i_dev.p2p_stop_find()
96 return [adv_id, rcvd_svc_name]
97
98 def p2ps_nonexact_seek(i_dev, r_dev, svc_name, srv_info=None, adv_num=None):
99 """P2PS nonexact service seek request"""
100 if adv_num is None:
101 adv_num = 1
102 if srv_info is not None:
103 ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '" + srv_info + "'")
104 else:
105 ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '")
106 if ev1 is None:
107 raise Exception("Failed to add Service Discovery request for nonexact seek request")
108 if "OK" not in i_dev.global_request("P2P_FIND 10 type=social seek="):
109 raise Exception("Failed to initiate seek")
110 ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
111 if ev1 is None:
112 raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
113 if r_dev.p2p_dev_addr() not in ev1:
114 raise Exception("Unexpected peer")
115 ev_list = []
116 for i in range (0, adv_num):
117 ev1 = i_dev.wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
118 if ev1 is None:
119 raise Exception("Failed to receive Service Discovery Response")
120 if r_dev.p2p_dev_addr() not in ev1:
121 raise Exception("Service Discovery response from Unknown Peer")
122 if srv_info is not None and srv_info not in ev1:
123 raise Exception("service info not available in Service Discovery response")
124 adv_id = ev1.split(" ")[3]
125 rcvd_svc_name = ev1.split(" ")[6]
126 ev_list.append(''.join([adv_id, ' ', rcvd_svc_name]))
127
128 i_dev.p2p_stop_find()
129 return ev_list
130
131 def p2ps_parse_event(ev, *args):
132 ret = ()
133 for arg in args:
134 m = re.search("\s+" + arg + r"=(\S+)", ev)
135 ret += (m.group(1) if m is not None else None,)
136 return ret
137
138 def p2ps_provision(seeker, advertiser, adv_id, auto_accept=True, method="1000",
139 adv_cpt=None, seeker_cpt=None, handler=None, adv_role=None,
140 seeker_role=None):
141 addr0 = seeker.p2p_dev_addr()
142 addr1 = advertiser.p2p_dev_addr()
143
144 seeker.asp_provision(addr1, adv_id=str(adv_id), adv_mac=addr1, session_id=1,
145 session_mac=addr0, method=method, cpt=seeker_cpt,
146 role=seeker_role)
147
148 if not auto_accept or method == "100":
149 pin = None
150 ev_pd_start = advertiser.wait_global_event(["P2PS-PROV-START"],
151 timeout=10)
152 if ev_pd_start is None:
153 raise Exception("P2PS-PROV-START timeout on Advertiser side")
154 peer = ev_pd_start.split()[1]
155 advert_id, advert_mac, session, session_mac =\
156 p2ps_parse_event(ev_pd_start, "adv_id", "adv_mac", "session", "mac")
157
158 ev = seeker.wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=10)
159 if ev is None:
160 raise Exception("P2P-PROV-DISC-FAILURE timeout on seeker side")
161
162 if handler:
163 handler(seeker, advertiser)
164
165 # Put seeker into a listen state, since we expect the deferred flow to
166 # continue.
167 seeker.p2p_ext_listen(500, 500)
168
169 if method == "100":
170 ev = advertiser.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"],
171 timeout=10)
172 if ev is None:
173 raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on advertiser side")
174 if addr0 not in ev:
175 raise Exception("Unknown peer " + addr0)
176 ev = seeker.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
177 timeout=10)
178 if ev is None:
179 raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on seeker side")
180 if addr1 not in ev:
181 raise Exception("Unknown peer " + addr1)
182 pin = ev.split()[2]
183 elif method == "8":
184 ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
185 timeout=10)
186 if ev is None:
187 raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side")
188 if addr0 not in ev:
189 raise Exception("Unknown peer " + addr0)
190 pin = ev.split()[2]
191
192 # Stop P2P_LISTEN before issuing P2P_ASP_PROVISION_RESP to avoid
193 # excessive delay and test case timeouts if it takes large number of
194 # retries to find the peer awake on its Listen channel.
195 advertiser.p2p_stop_find()
196
197 advertiser.asp_provision(peer, adv_id=advert_id, adv_mac=advert_mac,
198 session_id=int(session, 0),
199 session_mac=session_mac, status=12,
200 cpt=adv_cpt, role=adv_role)
201
202 ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
203 if ev1 is None:
204 raise Exception("P2PS-PROV-DONE timeout on seeker side")
205
206 ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
207 if ev2 is None:
208 raise Exception("P2PS-PROV-DONE timeout on advertiser side")
209
210 if method == "8":
211 ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"],
212 timeout=10)
213 if ev is None:
214 raise Exception("P2P-PROV-DISC-ENTER-PIN failed on seeker side")
215 if addr1 not in ev:
216 raise Exception("Unknown peer " + addr1)
217
218 seeker.p2p_cancel_ext_listen()
219 if pin is not None:
220 return ev1, ev2, pin
221 return ev1, ev2
222
223 # Auto-accept is true and the method is either P2PS or advertiser is DISPLAY
224 ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
225 if ev1 is None:
226 raise Exception("P2PS-PROV-DONE timeout on seeker side")
227
228 ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
229 if ev2 is None:
230 raise Exception("P2PS-PROV-DONE timeout on advertiser side")
231
232 if method == "8":
233 ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10)
234 if ev is None:
235 raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on seeker side")
236 if addr1 not in ev:
237 raise Exception("Unknown peer " + addr1)
238 ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
239 timeout=10)
240 if ev is None:
241 raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side")
242 if addr0 not in ev:
243 raise Exception("Unknown peer " + addr0)
244 pin = ev.split()[2]
245 return ev1, ev2, pin
246
247 return ev1, ev2
248
249 def p2ps_connect_pd(dev0, dev1, ev0, ev1, pin=None, join_extra="", go_ev=None):
250 conf_methods_map = {"8": "p2ps", "1": "display", "5": "keypad"}
251 peer0 = ev0.split()[1]
252 peer1 = ev1.split()[1]
253 status0, conncap0, adv_id0, adv_mac0, mac0, session0, dev_passwd_id0, go0, join0, feature_cap0, persist0, group_ssid0 =\
254 p2ps_parse_event(ev0, "status", "conncap", "adv_id", "adv_mac", "mac", "session", "dev_passwd_id", "go", "join", "feature_cap", "persist", "group_ssid")
255 status1, conncap1, adv_id1, adv_mac1, mac1, session1, dev_passwd_id1, go1, join1, feature_cap1, persist1, group_ssid1 =\
256 p2ps_parse_event(ev1, "status", "conncap", "adv_id", "adv_mac", "mac", "session", "dev_passwd_id", "go", "join", "feature_cap", "persist", "group_ssid")
257
258 if status0 != "0" and status0 != "12":
259 raise Exception("PD failed on " + dev0.p2p_dev_addr())
260
261 if status1 != "0" and status1 != "12":
262 raise Exception("PD failed on " + dev1.p2p_dev_addr())
263
264 if status0 == "12" and status1 == "12":
265 raise Exception("Both sides have status 12 which doesn't make sense")
266
267 if adv_id0 != adv_id1 or adv_id0 is None:
268 raise Exception("Adv. IDs don't match")
269
270 if adv_mac0 != adv_mac1 or adv_mac0 is None:
271 raise Exception("Adv. MACs don't match")
272
273 if session0 != session1 or session0 is None:
274 raise Exception("Session IDs don't match")
275
276 if mac0 != mac1 or mac0 is None:
277 raise Exception("Session MACs don't match")
278
279 #TODO: Validate feature capability
280
281 if bool(persist0) != bool(persist1):
282 raise Exception("Only one peer has persistent group")
283
284 if persist0 is None and not all([conncap0, conncap1, dev_passwd_id0,
285 dev_passwd_id1]):
286 raise Exception("Persistent group not used but conncap/dev_passwd_id are missing")
287
288 if persist0 is not None and any([conncap0, conncap1, dev_passwd_id0,
289 dev_passwd_id1]):
290 raise Exception("Persistent group is used but conncap/dev_passwd_id are present")
291
292 # Persistent Connection (todo: handle frequency)
293 if persist0 is not None:
294 dev0.p2p_stop_find()
295 if "OK" not in dev0.global_request("P2P_GROUP_ADD persistent=" + persist0 + " freq=2412"):
296 raise Exception("Could not re-start persistent group")
297 ev0 = dev0.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
298 if ev0 is None:
299 raise Exception("P2P-GROUP-STARTED timeout on " + dev0.p2p_dev_addr())
300 dev0.group_form_result(ev0)
301
302 if "OK" not in dev1.global_request("P2P_GROUP_ADD persistent=" + persist1 + " freq=2412"):
303 raise Exception("Could not re-start persistent group")
304 ev1 = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
305 if ev1 is None:
306 raise Exception("P2P-GROUP-STARTED timeout on " + dev1.p2p_dev_addr())
307 dev1.group_form_result(ev1)
308 if "GO" in ev0:
309 ev = dev0.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
310 if ev is None:
311 raise Exception("AP-STA-CONNECTED timeout on " + dev0.p2p_dev_addr())
312 else:
313 ev = dev1.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
314 if ev is None:
315 raise Exception("AP-STA-CONNECTED timeout on " + dev1.p2p_dev_addr())
316 else:
317 try:
318 method0 = conf_methods_map[dev_passwd_id0]
319 method1 = conf_methods_map[dev_passwd_id1]
320 except KeyError:
321 raise Exception("Unsupported method")
322
323 if method0 == "p2ps":
324 pin = "12345670"
325 if pin is None:
326 raise Exception("Pin is not provided")
327
328 if conncap0 == "1" and conncap1 == "1": # NEW/NEW - GON
329 if any([join0, join1, go0, go1]):
330 raise Exception("Unexpected join/go PD attributes")
331 dev0.p2p_listen()
332 if "OK" not in dev0.global_request("P2P_CONNECT " + peer0 + " " + pin + " " + method0 + " persistent auth"):
333 raise Exception("P2P_CONNECT fails on " + dev0.p2p_dev_addr())
334 if "OK" not in dev1.global_request("P2P_CONNECT " + peer1 + " " + pin + " " + method1 + " persistent"):
335 raise Exception("P2P_CONNECT fails on " + dev1.p2p_dev_addr())
336 ev = dev0.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
337 if ev is None:
338 raise Exception("GO Neg did not succeed on " + dev0.p2p_dev_addr())
339 ev = dev1.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
340 if ev is None:
341 raise Exception("GO Neg did not succeed on " + dev1.p2p_dev_addr())
342 ev = dev0.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
343 if ev is None:
344 raise Exception("P2P-GROUP-STARTED timeout on " + dev0.p2p_dev_addr())
345 dev0.group_form_result(ev)
346 ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
347 if ev is None:
348 raise Exception("P2P-GROUP-STARTED timeout on " + dev1.p2p_dev_addr())
349 dev1.group_form_result(ev)
350 else:
351 if conncap0 == "2" and conncap1 == "4": # dev0 CLI, dev1 GO
352 dev_cli, dev_go, go_if, join_address, go_method, cli_method, join_ssid = dev0, dev1, go1, join0, method1, method0, group_ssid0
353 elif conncap0 == "4" and conncap1 == "2": # dev0 GO, dev1 CLI
354 dev_cli, dev_go, go_if, join_address, go_method, cli_method, join_ssid = dev1, dev0, go0, join1, method0, method1, group_ssid1
355 else:
356 raise Exception("Bad connection capabilities")
357
358 if go_if is None:
359 raise Exception("Device " + dev_go.p2p_dev_addr() + " failed to become GO")
360 if join_address is None:
361 raise Exception("Device " + dev_cli.p2p_dev_addr() + " failed to become CLI")
362
363 if not dev_go.get_group_ifname().startswith('p2p-'):
364 if go_ev:
365 ev = go_ev
366 else:
367 ev = dev_go.wait_global_event(["P2P-GROUP-STARTED"],
368 timeout=10)
369 if ev is None:
370 raise Exception("P2P-GROUP-STARTED timeout on " + dev_go.p2p_dev_addr())
371 dev_go.group_form_result(ev)
372
373 if go_method != "p2ps":
374 ev = dev_go.group_request("WPS_PIN any " + pin)
375 if ev is None:
376 raise Exception("Failed to initiate pin authorization on registrar side")
377 if join_ssid:
378 group_ssid_txt = " ssid=" + join_ssid
379 else:
380 group_ssid_txt = ""
381 if "OK" not in dev_cli.global_request("P2P_CONNECT " + join_address + " " + pin + " " + cli_method + join_extra + " persistent join" + group_ssid_txt):
382 raise Exception("P2P_CONNECT failed on " + dev_cli.p2p_dev_addr())
383 ev = dev_cli.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
384 if ev is None:
385 raise Exception("P2P-GROUP-STARTED timeout on " + dev_cli.p2p_dev_addr())
386 dev_cli.group_form_result(ev)
387 ev = dev_go.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
388 if ev is None:
389 raise Exception("AP-STA-CONNECTED timeout on " + dev_go.p2p_dev_addr())
390
391 hwsim_utils.test_connectivity_p2p(dev0, dev1)
392
393 def set_no_group_iface(dev, enable):
394 if enable:
395 res = dev.get_driver_status()
396 if (int(res['capa.flags'], 0) & 0x20000000):
397 raise HwsimSkip("P2P Device used. Cannot set enable no_group_iface")
398 dev.global_request("SET p2p_no_group_iface 1")
399 else:
400 dev.global_request("SET p2p_no_group_iface 0")
401
402 def test_p2ps_exact_search(dev):
403 """P2PS exact service request"""
404 p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
405 srv_info='I can receive files upto size 2 GB')
406 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
407 svc_name='org.wi-fi.wfds.send.rx')
408
409 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
410 if ev0 is None:
411 raise Exception("Unable to remove the advertisement instance")
412
413 def test_p2ps_exact_search_srvinfo(dev):
414 """P2PS exact service request with service info"""
415 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
416 srv_info='I can receive files upto size 2 GB')
417 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
418 svc_name='org.wi-fi.wfds.send.rx',
419 srv_info='2 GB')
420
421 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
422 if ev0 is None:
423 raise Exception("Unable to remove the advertisement instance")
424
425 def test_p2ps_nonexact_search(dev):
426 """P2PS nonexact seek request"""
427 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.play.rx',
428 srv_info='I support Miracast Mode ')
429 ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
430 svc_name='org.wi-fi.wfds.play*')
431 adv_id = ev_list[0].split()[0]
432
433 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
434 if ev0 is None:
435 raise Exception("Unable to remove the advertisement instance")
436
437 def test_p2ps_nonexact_search_srvinfo(dev):
438 """P2PS nonexact seek request with service info"""
439 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
440 srv_info='I can receive files upto size 2 GB')
441 ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
442 svc_name='org.wi-fi.wfds.send*',
443 srv_info='2 GB')
444 adv_id = ev_list[0].split()[0]
445 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
446 if ev0 is None:
447 raise Exception("Unable to remove the advertisement instance")
448
449 def test_p2ps_connect_p2ps_method_nonautoaccept(dev):
450 """P2PS connect for non-auto-accept and P2PS config method"""
451 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
452 srv_info='I can receive files upto size 2 GB')
453 ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
454 svc_name='org.wi-fi.wfds.send*',
455 srv_info='2 GB')
456 adv_id = ev_list[0].split()[0]
457 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False)
458 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
459
460 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
461 if ev0 is None:
462 raise Exception("Unable to remove the advertisement instance")
463 remove_group(dev[0], dev[1])
464
465 def test_p2ps_connect_p2ps_method_autoaccept(dev):
466 """P2PS connection with P2PS default config method and auto-accept"""
467 p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
468 srv_info='I can receive files upto size 2 GB')
469 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
470 svc_name='org.wi-fi.wfds.send.rx',
471 srv_info='2 GB')
472
473 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
474 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
475
476 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
477 if ev0 is None:
478 raise Exception("Unable to remove the advertisement instance")
479 remove_group(dev[0], dev[1])
480
481 def test_p2ps_connect_keypad_method_nonautoaccept(dev):
482 """P2PS Connection with non-auto-accept and seeker having keypad method"""
483 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
484 srv_info='I can receive files upto size 2 GB')
485 ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
486 svc_name='org.wi-fi.wfds.send*',
487 srv_info='2 GB')
488 adv_id = ev_list[0].split()[0]
489
490 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False, method="8")
491 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
492
493 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
494 if ev0 is None:
495 raise Exception("Unable to remove the advertisement instance")
496 remove_group(dev[0], dev[1])
497
498 def test_p2ps_connect_display_method_nonautoaccept(dev):
499 """P2PS connection with non-auto-accept and seeker having display method"""
500 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
501 srv_info='I can receive files upto size 2 GB')
502 ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
503 svc_name='org.wi-fi.wfds*', srv_info='2 GB')
504 adv_id = ev_list[0].split()[0]
505
506 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False, method="100")
507 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
508
509 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
510 if ev0 is None:
511 raise Exception("Unable to remove the advertisement instance")
512 remove_group(dev[0], dev[1])
513
514 def test_p2ps_connect_keypad_method_autoaccept(dev):
515 """P2PS connection with auto-accept and keypad method on seeker side"""
516 p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
517 srv_info='I can receive files upto size 2 GB')
518 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
519 svc_name='org.wi-fi.wfds.send.rx',
520 srv_info='2 GB')
521
522 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
523 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
524
525 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
526 if ev0 is None:
527 raise Exception("Unable to remove the advertisement instance")
528 remove_group(dev[0], dev[1])
529
530 def test_p2ps_connect_display_method_autoaccept(dev):
531 """P2PS connection with auto-accept and display method on seeker side"""
532 p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
533 srv_info='I can receive files upto size 2 GB')
534 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
535 svc_name='org.wi-fi.wfds.send.rx',
536 srv_info='2 GB')
537
538 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="100")
539 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
540
541 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
542 if ev0 is None:
543 raise Exception("Unable to remove the advertisement instance")
544 remove_group(dev[0], dev[1])
545
546 def test_p2ps_connect_adv_go_p2ps_method(dev):
547 """P2PS auto-accept connection with advertisement as GO and P2PS method"""
548 p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
549 srv_info='I can receive files upto size 2 GB')
550 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
551 svc_name='org.wi-fi.wfds.send.rx',
552 srv_info='2 GB')
553
554 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
555 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
556
557 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
558 if ev0 is None:
559 raise Exception("Unable to remove the advertisement instance")
560 remove_group(dev[0], dev[1])
561
562 def test_p2ps_connect_adv_go_p2ps_method_group_iface(dev):
563 """P2PS auto-accept connection with advertisement as GO and P2PS method using separate group interface"""
564 set_no_group_iface(dev[0], 0)
565 set_no_group_iface(dev[1], 0)
566 p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
567 srv_info='I can receive files upto size 2 GB')
568 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
569 svc_name='org.wi-fi.wfds.send.rx',
570 srv_info='2 GB')
571
572 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
573 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
574
575 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
576 if ev0 is None:
577 raise Exception("Unable to remove the advertisement instance")
578 remove_group(dev[0], dev[1])
579
580 def test_p2ps_connect_adv_client_p2ps_method(dev):
581 """P2PS auto-accept connection with advertisement as Client and P2PS method"""
582 p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
583 srv_info='I can receive files upto size 2 GB')
584 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
585 svc_name='org.wi-fi.wfds.send.rx',
586 srv_info='2 GB')
587
588 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
589 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
590
591 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
592 if ev0 is None:
593 raise Exception("Unable to remove the advertisement instance")
594 remove_group(dev[0], dev[1])
595
596 def p2ps_connect_adv_go_pin_method(dev, keep_group=False):
597 p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
598 srv_info='I can receive files upto size 2 GB')
599 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
600 svc_name='org.wi-fi.wfds.send.rx',
601 srv_info='2 GB')
602 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
603 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
604
605 if not keep_group:
606 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
607 if ev0 is None:
608 raise Exception("Unable to remove the advertisement instance")
609 remove_group(dev[0], dev[1])
610
611 def test_p2ps_connect_adv_go_pin_method(dev):
612 """P2PS advertiser as GO with keypad config method on seeker side and auto-accept"""
613 p2ps_connect_adv_go_pin_method(dev)
614
615 def test_p2ps_connect_adv_client_pin_method(dev):
616 """P2PS advertiser as client with keypad config method on seeker side and auto-accept"""
617 dev[0].flush_scan_cache()
618 p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
619 srv_info='I can receive files upto size 2 GB')
620 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
621 svc_name='org.wi-fi.wfds.send.rx',
622 srv_info='2 GB')
623
624 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
625 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
626
627 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
628 if ev0 is None:
629 raise Exception("Unable to remove the advertisement instance")
630 remove_group(dev[0], dev[1])
631
632 def test_p2ps_service_discovery_multiple_queries(dev):
633 """P2P service discovery with multiple queries"""
634 addr0 = dev[0].p2p_dev_addr()
635 addr1 = dev[1].p2p_dev_addr()
636 adv_id1 = p2ps_advertise(r_dev=dev[0], r_role='0',
637 svc_name='org.wi-fi.wfds.send.tx',
638 srv_info='I can transfer files upto size of 2 GB')
639 adv_id2 = p2ps_advertise(r_dev=dev[0], r_role='0',
640 svc_name='org.wi-fi.wfds.send.rx',
641 srv_info='I can receive files upto size of 2 GB')
642 adv_id3 = p2ps_advertise(r_dev=dev[0], r_role='1',
643 svc_name='org.wi-fi.wfds.display.tx',
644 srv_info='Miracast Mode')
645 adv_id4 = p2ps_advertise(r_dev=dev[0], r_role='1',
646 svc_name='org.wi-fi.wfds.display.rx',
647 srv_info='Miracast Mode')
648
649 dev[1].global_request("P2P_SERV_DISC_REQ " + addr0 + " asp 1 org.wi-fi.wfds.display.tx 'Miracast Mode'")
650 dev[1].global_request("P2P_FIND 10 type=social seek=org.wi-fi.wfds.display.tx")
651 dev[1].global_request("P2P_SERV_DISC_REQ " + addr0 + " asp 2 org.wi-fi.wfds.send* 'size of 2 GB'")
652 dev[1].p2p_stop_find()
653 dev[1].global_request("P2P_FIND 10 type=social seek=")
654 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
655 if ev is None:
656 raise Exception("P2P Device Found timed out")
657 if addr0 not in ev:
658 raise Exception("Unexpected service discovery request source")
659 ev_list = []
660 for i in range(0, 3):
661 ev = dev[1].wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
662 if ev is None:
663 raise Exception("P2P Service discovery timed out")
664 if addr0 in ev:
665 ev_list.append(ev)
666 if len(ev_list) == 3:
667 break
668 dev[1].p2p_stop_find()
669
670 for test in [ ("seek=org.wi-fi.wfds.display.TX",
671 "asp_svc=org.wi-fi.wfds.display.tx"),
672 ("seek=foo seek=org.wi-fi.wfds.display.tx seek=bar",
673 "asp_svc=org.wi-fi.wfds.display.tx"),
674 ("seek=1 seek=2 seek=3 seek=org.wi-fi.wfds.display.tx seek=4 seek=5 seek=6",
675 "asp_svc=org.wi-fi.wfds.display.tx"),
676 ("seek=not-found", None),
677 ("seek=org.wi-fi.wfds", "asp_svc=org.wi-fi.wfds")]:
678 dev[2].global_request("P2P_FIND 10 type=social " + test[0])
679 if test[1] is None:
680 ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=1)
681 if ev is not None:
682 raise Exception("Unexpected device found: " + ev)
683 continue
684 ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
685 if ev is None:
686 raise Exception("P2P device discovery timed out (dev2)")
687 if test[1] not in ev:
688 raise Exception("Expected asp_svc not reported: " + ev)
689 dev[2].p2p_stop_find()
690 dev[2].request("P2P_FLUSH")
691
692 dev[0].p2p_stop_find()
693
694 ev1 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id1))
695 if ev1 is None:
696 raise Exception("Unable to remove the advertisement instance")
697 ev2 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id2))
698 if ev2 is None:
699 raise Exception("Unable to remove the advertisement instance")
700 ev3 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id3))
701 if ev3 is None:
702 raise Exception("Unable to remove the advertisement instance")
703 ev4 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id4))
704 if ev4 is None:
705 raise Exception("Unable to remove the advertisement instance")
706
707 if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
708 raise Exception("P2P_SERVICE_ADD failed")
709 if "OK" not in dev[0].global_request("P2P_SERVICE_DEL asp all"):
710 raise Exception("P2P_SERVICE_DEL asp all failed")
711 if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
712 raise Exception("P2P_SERVICE_ADD failed")
713 if "OK" not in dev[0].global_request("P2P_SERVICE_REP asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
714 raise Exception("P2P_SERVICE_REP failed")
715 if "FAIL" not in dev[0].global_request("P2P_SERVICE_REP asp 1 12345678 1 1108 org.wi-fi.wfds.Foo svc_info='Test'"):
716 raise Exception("Invalid P2P_SERVICE_REP accepted")
717 if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 a2345678 1 1108 org.wi-fi.wfds.something svc_info='Test'"):
718 raise Exception("P2P_SERVICE_ADD failed")
719 if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 a2345679 1 1108 org.wi-fi.wfds.Foo svc_info='Test'"):
720 raise Exception("P2P_SERVICE_ADD failed")
721
722 def get_ifnames():
723 with open('/proc/net/dev', 'r') as f:
724 data = f.read()
725 ifnames = []
726 for line in data.splitlines():
727 ifname = line.strip().split(' ')[0]
728 if ':' not in ifname:
729 continue
730 ifname = ifname.split(':')[0]
731 ifnames.append(ifname)
732 return ifnames
733
734 def p2ps_connect_p2ps_method(dev, keep_group=False, join_extra="", flush=True):
735 if flush:
736 dev[0].flush_scan_cache()
737 dev[1].flush_scan_cache()
738 p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
739 srv_info='I can receive files upto size 2 GB')
740 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
741 svc_name='org.wi-fi.wfds.send.rx',
742 srv_info='2 GB')
743 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
744 go_ev = None
745 if "join=" in ev0 and "go=" in ev1:
746 # dev[1] started GO and dev[0] is about to join it.
747 # Parse P2P-GROUP-STARTED from the GO to learn the operating frequency.
748 go_ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
749 if go_ev is None:
750 raise Exception("P2P-GROUP-STARTED timeout on dev1")
751 res = dev[1].group_form_result(go_ev)
752 if join_extra == "":
753 join_extra = " freq=" + res['freq']
754
755 ifnames = get_ifnames()
756 p2ps_connect_pd(dev[0], dev[1], ev0, ev1, join_extra=join_extra,
757 go_ev=go_ev)
758
759 grp_ifname0 = dev[0].get_group_ifname()
760 grp_ifname1 = dev[1].get_group_ifname()
761 if not keep_group:
762 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
763 if ev0 is None:
764 raise Exception("Unable to remove the advertisement instance")
765 ifnames = ifnames + get_ifnames()
766 remove_group(dev[0], dev[1])
767 ifnames = ifnames + get_ifnames()
768
769 return grp_ifname0, grp_ifname1, ifnames
770
771 def has_string_prefix(vals, prefix):
772 for val in vals:
773 if val.startswith(prefix):
774 return True
775 return False
776
777 def test_p2ps_connect_p2ps_method_1(dev):
778 """P2PS connection with P2PS method - no group interface"""
779 set_no_group_iface(dev[0], 1)
780 set_no_group_iface(dev[1], 1)
781
782 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
783 if grp_ifname0 != dev[0].ifname:
784 raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
785 if grp_ifname1 != dev[1].ifname:
786 raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
787 if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
788 raise Exception("dev0 group interface unexpectedly present")
789 if has_string_prefix(ifnames, 'p2p-' + grp_ifname1):
790 raise Exception("dev1 group interface unexpectedly present")
791
792 def test_p2ps_connect_p2ps_method_2(dev):
793 """P2PS connection with P2PS method - group interface on dev0"""
794 set_no_group_iface(dev[0], 0)
795 set_no_group_iface(dev[1], 1)
796
797 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
798 if not grp_ifname0.startswith('p2p-' + dev[0].ifname + '-'):
799 raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
800 if grp_ifname1 != dev[1].ifname:
801 raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
802 if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
803 raise Exception("dev0 group interface unexpectedly present")
804
805 def test_p2ps_connect_p2ps_method_3(dev):
806 """P2PS connection with P2PS method - group interface on dev1"""
807 set_no_group_iface(dev[0], 1)
808 set_no_group_iface(dev[1], 0)
809
810 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
811 if grp_ifname0 != dev[0].ifname:
812 raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
813 if not grp_ifname1.startswith('p2p-' + dev[1].ifname + '-'):
814 raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
815 if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
816 raise Exception("dev0 group interface unexpectedly present")
817
818 def test_p2ps_connect_p2ps_method_4(dev):
819 """P2PS connection with P2PS method - group interface on both"""
820 set_no_group_iface(dev[0], 0)
821 set_no_group_iface(dev[1], 0)
822
823 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
824 if not grp_ifname0.startswith('p2p-' + dev[0].ifname + '-'):
825 raise Exception("unexpected dev0 group ifname: " + res0['ifname'])
826 if not grp_ifname1.startswith('p2p-' + dev[1].ifname + '-'):
827 raise Exception("unexpected dev1 group ifname: " + res1['ifname'])
828
829 def test_p2ps_connect_adv_go_persistent(dev):
830 """P2PS auto-accept connection with advertisement as GO and having persistent group"""
831 go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
832 r_dev=dev[1], r_intent=0)
833 dev[0].remove_group()
834 dev[1].wait_go_ending_session()
835
836 p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
837 srv_info='I can receive files upto size 2 GB')
838 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
839 svc_name='org.wi-fi.wfds.send.rx',
840 srv_info='2 GB')
841 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
842 if "persist=" not in ev0 or "persist=" not in ev1:
843 raise Exception("Persistent group isn't used by peers")
844
845 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
846 remove_group(dev[0], dev[1])
847
848 def test_p2ps_adv_go_persistent_no_peer_entry(dev):
849 """P2PS advertisement as GO having persistent group (no peer entry)"""
850 go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
851 r_dev=dev[1], r_intent=0)
852 dev[0].remove_group()
853 dev[1].wait_go_ending_session()
854
855 p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
856 srv_info='I can receive files upto size 2 GB')
857 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
858 svc_name='org.wi-fi.wfds.send.rx',
859 srv_info='2 GB')
860 dev[0].global_request("P2P_FLUSH")
861 dev[0].p2p_listen()
862 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
863 if "persist=" not in ev0 or "persist=" not in ev1:
864 raise Exception("Persistent group isn't used by peers")
865
866 def test_p2ps_pd_follow_on_status_failure(dev):
867 """P2PS PD follow on request with status 11"""
868 addr0 = dev[0].p2p_dev_addr()
869 addr1 = dev[1].p2p_dev_addr()
870
871 p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
872 srv_info='I can receive files upto size 2 GB')
873 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
874 svc_name='org.wi-fi.wfds.send.rx',
875 srv_info='2 GB')
876 dev[1].asp_provision(addr0, adv_id=str(adv_id), adv_mac=addr0,
877 session_id=1, session_mac=addr1)
878 ev_pd_start = dev[0].wait_global_event(["P2PS-PROV-START"], timeout=10)
879 if ev_pd_start is None:
880 raise Exception("P2PS-PROV-START timeout on Advertiser side")
881 ev = dev[1].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=10)
882 if ev is None:
883 raise Exception("P2P-PROV-DISC-FAILURE timeout on seeker side")
884 dev[1].p2p_ext_listen(500, 500)
885 dev[0].p2p_stop_find()
886 dev[0].asp_provision(addr1, adv_id=str(adv_id), adv_mac=addr0, session_id=1,
887 session_mac=addr1, status=11, method=0)
888
889 ev = dev[1].wait_global_event(["P2PS-PROV-DONE"], timeout=10)
890 if ev is None:
891 raise Exception("P2P-PROV-DONE timeout on seeker side")
892 if adv_id not in ev:
893 raise Exception("P2P-PROV-DONE without adv_id on seeker side")
894 if "status=11" not in ev:
895 raise Exception("P2P-PROV-DONE without status on seeker side")
896
897 ev = dev[0].wait_global_event(["P2PS-PROV-DONE"], timeout=10)
898 if ev is None:
899 raise Exception("P2P-PROV-DONE timeout on advertiser side")
900 if adv_id not in ev:
901 raise Exception("P2P-PROV-DONE without adv_id on advertiser side")
902 if "status=11" not in ev:
903 raise Exception("P2P-PROV-DONE without status on advertiser side")
904
905 def test_p2ps_client_probe(dev):
906 """P2PS CLI discoverability on operating channel"""
907 cli_probe = dev[0].global_request("SET p2p_cli_probe 1")
908 p2ps_connect_p2ps_method(dev, keep_group=True)
909 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[2], r_dev=dev[0],
910 svc_name='org.wi-fi.wfds.send.rx',
911 single_peer_expected=False)
912 dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
913 remove_group(dev[0], dev[1])
914
915 def test_p2ps_go_probe(dev):
916 """P2PS GO discoverability on operating channel"""
917 p2ps_connect_adv_go_pin_method(dev, keep_group=True)
918 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[2], r_dev=dev[0],
919 svc_name='org.wi-fi.wfds.send.rx',
920 single_peer_expected=False)
921 dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
922 remove_group(dev[0], dev[1])
923
924 def test_p2ps_wildcard_p2ps(dev):
925 """P2PS wildcard SD Probe Request/Response"""
926 p2ps_wildcard = "org.wi-fi.wfds"
927
928 adv_id = p2ps_advertise(r_dev=dev[0], r_role='1',
929 svc_name='org.foo.service',
930 srv_info='I can do stuff')
931 adv_id2 = p2ps_advertise(r_dev=dev[0], r_role='1',
932 svc_name='org.wi-fi.wfds.send.rx',
933 srv_info='I can receive files upto size 2 GB')
934
935 if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=org.foo.service seek=" + p2ps_wildcard):
936 raise Exception("Failed on P2P_FIND command")
937
938 ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
939 if ev1 is None:
940 raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
941 if dev[0].p2p_dev_addr() not in ev1:
942 raise Exception("Unexpected peer")
943
944 ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
945 if ev2 is None:
946 raise Exception("P2P-DEVICE-FOUND timeout on seeker side (2)")
947 if dev[0].p2p_dev_addr() not in ev2:
948 raise Exception("Unexpected peer (2)")
949
950 if p2ps_wildcard not in ev1 + ev2:
951 raise Exception("P2PS Wildcard name not found in P2P-DEVICE-FOUND event")
952 if "org.foo.service" not in ev1 + ev2:
953 raise Exception("Vendor specific service name not found in P2P-DEVICE-FOUND event")
954
955 if "OK" not in dev[1].global_request("P2P_STOP_FIND"):
956 raise Exception("P2P_STOP_FIND failed")
957 dev[1].dump_monitor()
958
959 res = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
960 if res is None:
961 raise Exception("Unable to remove the advertisement instance")
962
963 if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=" + p2ps_wildcard):
964 raise Exception("Failed on P2P_FIND command")
965
966 ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
967 if ev1 is None:
968 raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
969 if dev[0].p2p_dev_addr() not in ev1:
970 raise Exception("Unexpected peer")
971 if p2ps_wildcard not in ev1:
972 raise Exception("P2PS Wildcard name not found in P2P-DEVICE-FOUND event (2)")
973 dev[1].dump_monitor()
974
975 res = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id2))
976 if res is None:
977 raise Exception("Unable to remove the advertisement instance 2")
978
979 if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=" + p2ps_wildcard):
980 raise Exception("Failed on P2P_FIND command")
981
982 ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=2)
983 if ev1 is not None:
984 raise Exception("Unexpected P2P-DEVICE-FOUND event on seeker side")
985 dev[1].p2p_stop_find()
986 dev[1].dump_monitor()
987
988 def test_p2ps_many_services_in_probe(dev):
989 """P2PS with large number of services in Probe Request/Response"""
990 long1 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.a'
991 long2 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.b'
992 long3 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.c'
993 long4 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.d'
994 long5 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.e'
995 for name in [ long1, long2, long3, long4, long5 ]:
996 p2ps_advertise(r_dev=dev[0], r_role='1',
997 svc_name=name,
998 srv_info='I can do stuff')
999
1000 if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=%s seek=%s seek=%s seek=%s seek=%s" % (long1, long2, long3, long4, long5)):
1001 raise Exception("Failed on P2P_FIND command")
1002
1003 events = ""
1004 # Note: Require only four events since all the services do not fit within
1005 # the length limit.
1006 for i in range(4):
1007 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
1008 if ev is None:
1009 raise Exception("Missing P2P-DEVICE-FOUND")
1010 events = events + ev
1011 dev[1].p2p_stop_find()
1012 dev[1].dump_monitor()
1013 for name in [ long2, long3, long4, long5 ]:
1014 if name not in events:
1015 raise Exception("Service missing from peer events")
1016
1017 def p2ps_test_feature_capability_cpt(dev, adv_cpt, seeker_cpt, adv_role,
1018 result):
1019 p2ps_advertise(r_dev=dev[0], r_role=adv_role,
1020 svc_name='org.wi-fi.wfds.send.rx',
1021 srv_info='I can receive files upto size 2 GB', cpt=adv_cpt)
1022 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1023 svc_name='org.wi-fi.wfds.send.rx',
1024 srv_info='2 GB')
1025 auto_accept = adv_role != "0"
1026 ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id,
1027 auto_accept=auto_accept, adv_cpt=adv_cpt,
1028 seeker_cpt=seeker_cpt, method="8")
1029
1030 status0, fcap0 = p2ps_parse_event(ev0, "status", "feature_cap")
1031 status1, fcap1 = p2ps_parse_event(ev0, "status", "feature_cap")
1032
1033 if fcap0 is None:
1034 raise Exception("Bad feature capability on Seeker side")
1035 if fcap1 is None:
1036 raise Exception("Bad feature capability on Advertiser side")
1037 if fcap0 != fcap1:
1038 raise Exception("Incompatible feature capability values")
1039
1040 if status0 not in ("0", "12") or status1 not in ("0", "12"):
1041 raise Exception("Unexpected PD result status")
1042
1043 if result == "UDP" and fcap0[1] != "1":
1044 raise Exception("Unexpected CPT feature capability value (expected: UDP)")
1045 elif result == "MAC" and fcap0[1] != "2":
1046 raise Exception("Unexpected CPT feature capability value (expected: MAC)")
1047
1048 ev = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
1049 if ev is None:
1050 raise Exception("Unable to remove the advertisement instance")
1051
1052 def test_p2ps_feature_capability_mac_autoaccept(dev):
1053 """P2PS PD Feature Capability CPT: advertiser MAC, seeker UDP:MAC, autoaccept"""
1054 p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC", seeker_cpt="UDP:MAC",
1055 adv_role="4", result="MAC")
1056
1057 def test_p2ps_feature_capability_mac_nonautoaccept(dev):
1058 """P2PS PD Feature Capability CPT: advertiser:MAC, seeker UDP:MAC, nonautoaccept"""
1059 p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC", seeker_cpt="UDP:MAC",
1060 adv_role="0", result="MAC")
1061
1062 def test_p2ps_feature_capability_mac_udp_autoaccept(dev):
1063 """P2PS PD Feature Capability CPT: advertiser MAC:UDP, seeker UDP:MAC, autoaccept"""
1064 p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC:UDP",
1065 seeker_cpt="UDP:MAC", adv_role="2",
1066 result="MAC")
1067
1068 def test_p2ps_feature_capability_mac_udp_nonautoaccept(dev):
1069 """P2PS PD Feature Capability CPT: advertiser MAC:UDP, seeker UDP:MAC, nonautoaccept"""
1070 p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC:UDP",
1071 seeker_cpt="UDP:MAC", adv_role="0",
1072 result="UDP")
1073
1074 def test_p2ps_feature_capability_udp_mac_autoaccept(dev):
1075 """P2PS PD Feature Capability CPT: advertiser UDP:MAC, seeker MAC:UDP, autoaccept"""
1076 p2ps_test_feature_capability_cpt(dev, adv_cpt="UDP:MAC",
1077 seeker_cpt="MAC:UDP", adv_role="2",
1078 result="UDP")
1079
1080 def test_p2ps_feature_capability_udp_mac_nonautoaccept(dev):
1081 """P2PS PD Feature Capability CPT: advertiser UDP:MAC, seeker MAC:UDP, nonautoaccept"""
1082 p2ps_test_feature_capability_cpt(dev, adv_cpt="UDP:MAC",
1083 seeker_cpt="MAC:UDP", adv_role="0",
1084 result="MAC")
1085
1086 def test_p2ps_channel_one_connected(dev, apdev):
1087 """P2PS connection with P2PS method - one of the stations connected"""
1088 set_no_group_iface(dev[0], 0)
1089 set_no_group_iface(dev[1], 0)
1090
1091 try:
1092 hapd = hostapd.add_ap(apdev[0]['ifname'],
1093 { "ssid": 'bss-2.4ghz', "channel": '7' })
1094 dev[1].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2442")
1095
1096 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev, keep_group=True, join_extra=" freq=2442")
1097 freq = dev[0].get_group_status_field('freq');
1098
1099 if freq != '2442':
1100 raise Exception('Unexpected frequency for group 2442 != ' + freq)
1101 finally:
1102 remove_group(dev[0], dev[1])
1103 dev[0].global_request("P2P_SERVICE_DEL asp all")
1104
1105 def set_random_listen_chan(dev):
1106 chan = random.randrange(0, 3) * 5 + 1
1107 dev.global_request("P2P_SET listen_channel %d" % chan)
1108
1109 def test_p2ps_channel_both_connected_same(dev, apdev):
1110 """P2PS connection with P2PS method - stations connected on same channel"""
1111 set_no_group_iface(dev[2], 0)
1112 set_no_group_iface(dev[1], 0)
1113
1114 dev[2].global_request("P2P_SET listen_channel 6")
1115 dev[1].global_request("P2P_SET listen_channel 6")
1116
1117 dev[1].flush_scan_cache()
1118 dev[2].flush_scan_cache()
1119
1120 try:
1121 hapd = hostapd.add_ap(apdev[0]['ifname'],
1122 { "ssid": 'bss-2.4ghz', "channel": '6' })
1123
1124 dev[2].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2437")
1125 dev[1].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2437")
1126
1127 tmpdev = [ dev[2], dev[1] ]
1128 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(tmpdev, keep_group=True, join_extra=" freq=2437", flush=False)
1129 freq = dev[2].get_group_status_field('freq');
1130
1131 if freq != '2437':
1132 raise Exception('Unexpected frequency for group 2437 != ' + freq)
1133 finally:
1134 remove_group(dev[2], dev[1])
1135 dev[2].global_request("P2P_SERVICE_DEL asp all")
1136 for i in range(1, 3):
1137 set_random_listen_chan(dev[i])
1138
1139 def disconnect_handler(seeker, advertiser):
1140 advertiser.request("DISCONNECT")
1141 advertiser.wait_disconnected(timeout=1)
1142
1143 def test_p2ps_channel_both_connected_different(dev, apdev):
1144 """P2PS connection with P2PS method - stations connected on different channel"""
1145 if dev[0].get_mcc() > 1:
1146 raise HwsimSkip('Skip due to MCC being enabled')
1147
1148 set_no_group_iface(dev[0], 0)
1149 set_no_group_iface(dev[1], 0)
1150
1151 try:
1152 hapd1 = hostapd.add_ap(apdev[0]['ifname'],
1153 { "ssid": 'bss-channel-3', "channel": '3' })
1154
1155 hapd2 = hostapd.add_ap(apdev[1]['ifname'],
1156 { "ssid": 'bss-channel-10', "channel": '10' })
1157
1158 dev[0].connect("bss-channel-3", key_mgmt="NONE", scan_freq="2422")
1159 dev[1].connect("bss-channel-10", key_mgmt="NONE", scan_freq="2457")
1160
1161 p2ps_advertise(r_dev=dev[0], r_role='2',
1162 svc_name='org.wi-fi.wfds.send.rx',
1163 srv_info='I can receive files upto size 2 GB')
1164 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1165 svc_name='org.wi-fi.wfds.send.rx',
1166 srv_info='2 GB')
1167
1168 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
1169 handler=disconnect_handler)
1170 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
1171 freq = dev[0].get_group_status_field('freq');
1172 if freq != '2457':
1173 raise Exception('Unexpected frequency for group 2457 != ' + freq)
1174 finally:
1175 remove_group(dev[0], dev[1])
1176 dev[0].global_request("P2P_SERVICE_DEL asp all")
1177
1178 def test_p2ps_channel_both_connected_different_mcc(dev, apdev):
1179 """P2PS connection with P2PS method - stations connected on different channels with mcc"""
1180 if dev[0].get_mcc() == 1:
1181 raise HwsimSkip('Skip case due to MCC not enabled')
1182
1183 set_no_group_iface(dev[0], 0)
1184 set_no_group_iface(dev[1], 0)
1185
1186 try:
1187 hapd1 = hostapd.add_ap(apdev[0]['ifname'],
1188 { "ssid": 'bss-channel-3', "channel": '3' })
1189
1190 hapd2 = hostapd.add_ap(apdev[1]['ifname'],
1191 { "ssid": 'bss-channel-10', "channel": '10' })
1192
1193 dev[0].connect("bss-channel-3", key_mgmt="NONE", scan_freq="2422")
1194 dev[1].connect("bss-channel-10", key_mgmt="NONE", scan_freq="2457")
1195
1196 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev, keep_group=True)
1197 freq = dev[0].get_group_status_field('freq');
1198
1199 if freq != '2422' and freq != '2457':
1200 raise Exception('Unexpected frequency for group =' + freq)
1201 finally:
1202 remove_group(dev[0], dev[1])
1203 dev[0].global_request("P2P_SERVICE_DEL asp all")
1204
1205 def clear_disallow_handler(seeker, advertiser):
1206 advertiser.global_request("P2P_SET disallow_freq ")
1207
1208 def test_p2ps_channel_disallow_freq(dev, apdev):
1209 """P2PS connection with P2PS method - disallow freqs"""
1210 set_no_group_iface(dev[0], 0)
1211 set_no_group_iface(dev[1], 0)
1212
1213 try:
1214 dev[0].global_request("P2P_SET disallow_freq 2412-2457")
1215 dev[1].global_request("P2P_SET disallow_freq 2417-2462")
1216
1217 p2ps_advertise(r_dev=dev[0], r_role='2',
1218 svc_name='org.wi-fi.wfds.send.rx',
1219 srv_info='I can receive files upto size 2 GB')
1220
1221 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1222 svc_name='org.wi-fi.wfds.send.rx',
1223 srv_info='2 GB')
1224
1225 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
1226 handler=clear_disallow_handler)
1227 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
1228
1229 freq = dev[0].get_group_status_field('freq');
1230 if freq != '2412':
1231 raise Exception('Unexpected frequency for group 2412 != ' + freq)
1232 finally:
1233 remove_group(dev[0], dev[1])
1234 dev[0].global_request("P2P_SERVICE_DEL asp all")
1235 dev[0].global_request("P2P_SET disallow_freq ")
1236 dev[1].global_request("P2P_SET disallow_freq ")
1237
1238 def test_p2ps_channel_sta_connected_disallow_freq(dev, apdev):
1239 """P2PS connection with P2PS method - one station and disallow freqs"""
1240 if dev[0].get_mcc() > 1:
1241 raise HwsimSkip('Skip due to MCC being enabled')
1242
1243 set_no_group_iface(dev[0], 0)
1244 set_no_group_iface(dev[1], 0)
1245
1246 try:
1247 dev[0].global_request("P2P_SET disallow_freq 2437")
1248 hapd = hostapd.add_ap(apdev[0]['ifname'],
1249 { "ssid": 'bss-channel-6', "channel": '6' })
1250
1251 dev[1].connect("bss-channel-6", key_mgmt="NONE", scan_freq="2437")
1252
1253 p2ps_advertise(r_dev=dev[0], r_role='2',
1254 svc_name='org.wi-fi.wfds.send.rx',
1255 srv_info='I can receive files upto size 2 GB')
1256 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1257 svc_name='org.wi-fi.wfds.send.rx',
1258 srv_info='2 GB')
1259
1260 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
1261 handler=clear_disallow_handler)
1262 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
1263
1264 freq = dev[0].get_group_status_field('freq');
1265 if freq != '2437':
1266 raise Exception('Unexpected frequency for group 2437 != ' + freq)
1267 finally:
1268 remove_group(dev[0], dev[1])
1269 dev[0].global_request("P2P_SET disallow_freq ")
1270 dev[0].global_request("P2P_SERVICE_DEL asp all")
1271
1272 def test_p2ps_channel_sta_connected_disallow_freq_mcc(dev, apdev):
1273 """P2PS connection with P2PS method - one station and disallow freqs with mcc"""
1274 with HWSimRadio(n_channels=2) as (radio, iface):
1275 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1276 wpas.interface_add(iface)
1277
1278 if wpas.get_mcc() < 2:
1279 raise Exception("New radio does not support MCC")
1280
1281 set_no_group_iface(dev[0], 0)
1282 set_no_group_iface(wpas, 0)
1283
1284 try:
1285 dev[0].global_request("P2P_SET disallow_freq 2437")
1286 hapd1 = hostapd.add_ap(apdev[0]['ifname'],
1287 { "ssid": 'bss-channel-6', "channel": '6' })
1288
1289 wpas.connect("bss-channel-6", key_mgmt="NONE", scan_freq="2437")
1290
1291 tmpdev = [ dev[0], wpas ]
1292 (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(tmpdev, keep_group=True)
1293
1294 freq = dev[0].get_group_status_field('freq');
1295 if freq == '2437':
1296 raise Exception('Unexpected frequency=2437')
1297 finally:
1298 remove_group(dev[0], wpas)
1299 dev[0].global_request("P2P_SET disallow_freq ")
1300 dev[0].global_request("P2P_SERVICE_DEL asp all")
1301
1302 def test_p2ps_active_go_adv(dev, apdev):
1303 """P2PS connection with P2PS method - active GO on advertiser"""
1304 set_no_group_iface(dev[0], 0)
1305 set_no_group_iface(dev[1], 0)
1306
1307 try:
1308 # Add a P2P GO
1309 dev[0].global_request("P2P_GROUP_ADD persistent")
1310 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1311 if ev is None:
1312 raise Exception("P2P-GROUP-STARTED timeout on " + dev[0].p2p_dev_addr())
1313
1314 dev[0].group_form_result(ev)
1315
1316 p2ps_advertise(r_dev=dev[0], r_role='4',
1317 svc_name='org.wi-fi.wfds.send.rx',
1318 srv_info='I can receive files upto size 2 GB')
1319 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1320 svc_name='org.wi-fi.wfds.send.rx',
1321 single_peer_expected=False)
1322
1323 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
1324
1325 # explicitly stop find/listen as otherwise the long listen started by
1326 # the advertiser would prevent the seeker to connect with the P2P GO
1327 dev[0].p2p_stop_find()
1328 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
1329 finally:
1330 remove_group(dev[0], dev[1])
1331 dev[0].global_request("P2P_SERVICE_DEL asp all")
1332
1333 def test_p2ps_active_go_seeker(dev, apdev):
1334 """P2PS connection with P2PS method - active GO on seeker"""
1335 set_no_group_iface(dev[0], 0)
1336 set_no_group_iface(dev[1], 0)
1337
1338 try:
1339 # Add a P2P GO on the seeker
1340 dev[1].global_request("P2P_GROUP_ADD persistent")
1341 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1342 if ev is None:
1343 raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
1344
1345 res = dev[1].group_form_result(ev)
1346
1347 p2ps_advertise(r_dev=dev[0], r_role='2',
1348 svc_name='org.wi-fi.wfds.send.rx',
1349 srv_info='I can receive files upto size 2 GB')
1350 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1351 svc_name='org.wi-fi.wfds.send.rx',
1352 srv_info='2 GB')
1353
1354 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
1355 p2ps_connect_pd(dev[0], dev[1], ev0, ev1,
1356 join_extra=" freq=" + res['freq'])
1357 finally:
1358 remove_group(dev[0], dev[1])
1359 dev[0].global_request("P2P_SERVICE_DEL asp all")
1360
1361 def test_p2ps_channel_active_go_and_station_same(dev, apdev):
1362 """P2PS connection, active P2P GO and station on channel"""
1363 set_no_group_iface(dev[2], 0)
1364 set_no_group_iface(dev[1], 0)
1365
1366 dev[2].global_request("P2P_SET listen_channel 11")
1367 dev[1].global_request("P2P_SET listen_channel 11")
1368 try:
1369 hapd = hostapd.add_ap(apdev[0]['ifname'],
1370 { "ssid": 'bss-channel-11', "channel": '11' })
1371
1372 dev[2].connect("bss-channel-11", key_mgmt="NONE", scan_freq="2462")
1373
1374 # Add a P2P GO on the seeker
1375 dev[1].global_request("P2P_GROUP_ADD freq=2462 persistent")
1376 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1377 if ev is None:
1378 raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
1379
1380 dev[1].group_form_result(ev)
1381
1382 p2ps_advertise(r_dev=dev[2], r_role='2',
1383 svc_name='org.wi-fi.wfds.send.rx',
1384 srv_info='I can receive files upto size 2 GB')
1385 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[2],
1386 svc_name='org.wi-fi.wfds.send.rx',
1387 srv_info='2 GB')
1388
1389 ev1, ev0 = p2ps_provision(dev[1], dev[2], adv_id)
1390 p2ps_connect_pd(dev[2], dev[1], ev0, ev1, join_extra=" freq=2462")
1391 finally:
1392 remove_group(dev[2], dev[1])
1393 dev[2].global_request("P2P_SERVICE_DEL asp all")
1394 for i in range(1, 3):
1395 set_random_listen_chan(dev[i])
1396
1397 def test_p2ps_channel_active_go_and_station_different(dev, apdev):
1398 """P2PS connection, active P2P GO and station on channel"""
1399 if dev[0].get_mcc() > 1:
1400 raise HwsimSkip('Skip due to MCC being enabled')
1401
1402 set_no_group_iface(dev[0], 0)
1403 set_no_group_iface(dev[1], 0)
1404
1405 try:
1406 hapd = hostapd.add_ap(apdev[0]['ifname'],
1407 { "ssid": 'bss-channel-2', "channel": '2' })
1408
1409 dev[0].connect("bss-channel-2", key_mgmt="NONE", scan_freq="2417")
1410
1411 # Add a P2P GO on the seeker. Force the listen channel to be the same,
1412 # as extended listen will not kick as long as P2P GO is waiting for
1413 # initial connection.
1414 dev[1].global_request("P2P_SET listen_channel 11")
1415 dev[1].global_request("P2P_GROUP_ADD freq=2462 persistent")
1416 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1417 if ev is None:
1418 raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
1419
1420 dev[1].group_form_result(ev)
1421
1422 p2ps_advertise(r_dev=dev[0], r_role='2',
1423 svc_name='org.wi-fi.wfds.send.rx',
1424 srv_info='I can receive files upto size 2 GB')
1425 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1426 svc_name='org.wi-fi.wfds.send.rx',
1427 srv_info='2 GB')
1428
1429 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
1430 handler=disconnect_handler, adv_role='2',
1431 seeker_role='4')
1432 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
1433 freq = dev[0].get_group_status_field('freq');
1434 if freq != '2462':
1435 raise Exception('Unexpected frequency for group 2462!=' + freq)
1436 finally:
1437 dev[0].global_request("P2P_SERVICE_DEL asp all")
1438 set_random_listen_chan(dev[1])
1439
1440 def test_p2ps_channel_active_go_and_station_different_mcc(dev, apdev):
1441 """P2PS connection, active P2P GO and station on channel"""
1442 if dev[0].get_mcc() == 1:
1443 raise HwsimSkip('Skip due to MCC not being enabled')
1444
1445 set_no_group_iface(dev[0], 0)
1446 set_no_group_iface(dev[1], 0)
1447
1448 try:
1449 hapd = hostapd.add_ap(apdev[0]['ifname'],
1450 { "ssid": 'bss-channel-6', "channel": '6' })
1451
1452 dev[0].connect("bss-channel-6", key_mgmt="NONE", scan_freq="2437")
1453
1454 # Add a P2P GO on the seeker
1455 dev[1].global_request("P2P_GROUP_ADD freq=2462 persistent")
1456 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1457 if ev is None:
1458 raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
1459
1460 dev[1].group_form_result(ev)
1461
1462 p2ps_advertise(r_dev=dev[0], r_role='2',
1463 svc_name='org.wi-fi.wfds.send.rx',
1464 srv_info='I can receive files upto size 2 GB')
1465 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
1466 svc_name='org.wi-fi.wfds.send.rx',
1467 srv_info='2 GB')
1468
1469 ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
1470 p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
1471 finally:
1472 remove_group(dev[0], dev[1])
1473 dev[0].request("DISCONNECT")
1474 hapd.disable()
1475 dev[0].global_request("P2P_SERVICE_DEL asp all")
1476
1477 def test_p2ps_connect_p2p_device(dev):
1478 """P2PS connection using cfg80211 P2P Device"""
1479 run_p2ps_connect_p2p_device(dev, 0)
1480
1481 def test_p2ps_connect_p2p_device_no_group_iface(dev):
1482 """P2PS connection using cfg80211 P2P Device (no separate group interface)"""
1483 run_p2ps_connect_p2p_device(dev, 1)
1484
1485 def run_p2ps_connect_p2p_device(dev, no_group_iface):
1486 with HWSimRadio(use_p2p_device=True) as (radio, iface):
1487 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1488 wpas.interface_add(iface)
1489 wpas.global_request("SET p2p_no_group_iface %d" % no_group_iface)
1490
1491 p2ps_advertise(r_dev=dev[0], r_role='1',
1492 svc_name='org.wi-fi.wfds.send.rx',
1493 srv_info='I can receive files upto size 2 GB')
1494 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=wpas, r_dev=dev[0],
1495 svc_name='org.wi-fi.wfds.send.rx',
1496 srv_info='2 GB')
1497
1498 ev1, ev0 = p2ps_provision(wpas, dev[0], adv_id)
1499 p2ps_connect_pd(dev[0], wpas, ev0, ev1)
1500
1501 ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
1502 if ev0 is None:
1503 raise Exception("Unable to remove the advertisement instance")
1504 remove_group(dev[0], wpas)
1505
1506 def test_p2ps_connect_p2p_device2(dev):
1507 """P2PS connection using cfg80211 P2P Device (reverse)"""
1508 run_p2ps_connect_p2p_device2(dev, 0)
1509
1510 def test_p2ps_connect_p2p_device2_no_group_iface(dev):
1511 """P2PS connection using cfg80211 P2P Device (reverse) (no separate group interface)"""
1512 run_p2ps_connect_p2p_device2(dev, 1)
1513
1514 def run_p2ps_connect_p2p_device2(dev, no_group_iface):
1515 with HWSimRadio(use_p2p_device=True) as (radio, iface):
1516 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1517 wpas.interface_add(iface)
1518 wpas.global_request("SET p2p_no_group_iface %d" % no_group_iface)
1519
1520 p2ps_advertise(r_dev=wpas, r_role='1',
1521 svc_name='org.wi-fi.wfds.send.rx',
1522 srv_info='I can receive files upto size 2 GB')
1523 [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[0], r_dev=wpas,
1524 svc_name='org.wi-fi.wfds.send.rx',
1525 srv_info='2 GB')
1526
1527 ev1, ev0 = p2ps_provision(dev[0], wpas, adv_id)
1528 p2ps_connect_pd(wpas, dev[0], ev0, ev1)
1529
1530 ev0 = wpas.global_request("P2P_SERVICE_DEL asp " + str(adv_id))
1531 if ev0 is None:
1532 raise Exception("Unable to remove the advertisement instance")
1533 remove_group(wpas, dev[0])