test_p2p_device.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. # cfg80211 P2P Device
  2. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import time
  9. from wpasupplicant import WpaSupplicant
  10. from p2p_utils import *
  11. from test_nfc_p2p import set_ip_addr_info, check_ip_addr, grpform_events
  12. from hwsim import HWSimRadio
  13. from utils import HwsimSkip
  14. import hostapd
  15. import hwsim_utils
  16. def test_p2p_device_grpform(dev, apdev):
  17. """P2P group formation with driver using cfg80211 P2P Device"""
  18. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  19. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  20. wpas.interface_add(iface)
  21. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  22. r_dev=wpas, r_intent=0)
  23. check_grpform_results(i_res, r_res)
  24. wpas.dump_monitor()
  25. remove_group(dev[0], wpas)
  26. wpas.dump_monitor()
  27. if not r_res['ifname'].startswith('p2p-' + iface):
  28. raise Exception("Unexpected group ifname: " + r_res['ifname'])
  29. res = wpas.global_request("IFNAME=p2p-dev-" + iface + " STATUS-DRIVER")
  30. lines = res.splitlines()
  31. found = False
  32. for l in lines:
  33. try:
  34. [name,value] = l.split('=', 1)
  35. if name == "wdev_id":
  36. found = True
  37. break
  38. except ValueError:
  39. pass
  40. if not found:
  41. raise Exception("wdev_id not found")
  42. def test_p2p_device_grpform2(dev, apdev):
  43. """P2P group formation with driver using cfg80211 P2P Device (reverse)"""
  44. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  45. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  46. wpas.interface_add(iface)
  47. [i_res, r_res] = go_neg_pin_authorized(i_dev=wpas, i_intent=15,
  48. r_dev=dev[0], r_intent=0)
  49. check_grpform_results(i_res, r_res)
  50. wpas.dump_monitor()
  51. remove_group(wpas, dev[0])
  52. wpas.dump_monitor()
  53. if not i_res['ifname'].startswith('p2p-' + iface):
  54. raise Exception("Unexpected group ifname: " + i_res['ifname'])
  55. def test_p2p_device_grpform_no_group_iface(dev, apdev):
  56. """P2P group formation with driver using cfg80211 P2P Device but no separate group interface"""
  57. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  58. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  59. wpas.interface_add(iface)
  60. wpas.global_request("SET p2p_no_group_iface 1")
  61. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  62. r_dev=wpas, r_intent=0)
  63. check_grpform_results(i_res, r_res)
  64. wpas.dump_monitor()
  65. remove_group(dev[0], wpas)
  66. wpas.dump_monitor()
  67. if r_res['ifname'] != iface:
  68. raise Exception("Unexpected group ifname: " + r_res['ifname'])
  69. def test_p2p_device_grpform_no_group_iface2(dev, apdev):
  70. """P2P group formation with driver using cfg80211 P2P Device but no separate group interface (reverse)"""
  71. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  72. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  73. wpas.interface_add(iface)
  74. wpas.global_request("SET p2p_no_group_iface 1")
  75. [i_res, r_res] = go_neg_pin_authorized(i_dev=wpas, i_intent=15,
  76. r_dev=dev[0], r_intent=0)
  77. check_grpform_results(i_res, r_res)
  78. wpas.dump_monitor()
  79. remove_group(dev[0], wpas)
  80. wpas.dump_monitor()
  81. if i_res['ifname'] != iface:
  82. raise Exception("Unexpected group ifname: " + i_res['ifname'])
  83. def test_p2p_device_group_remove(dev, apdev):
  84. """P2P group removal via the P2P ctrl interface with driver using cfg80211 P2P Device"""
  85. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  86. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  87. wpas.interface_add(iface)
  88. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  89. r_dev=wpas, r_intent=0)
  90. check_grpform_results(i_res, r_res)
  91. # Issue the remove request on the interface which will be removed
  92. p2p_iface_wpas = WpaSupplicant(ifname=r_res['ifname'])
  93. res = p2p_iface_wpas.request("P2P_GROUP_REMOVE *")
  94. if "OK" not in res:
  95. raise Exception("Failed to remove P2P group")
  96. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  97. if ev is None:
  98. raise Exception("Group removal event not received")
  99. if not wpas.global_ping():
  100. raise Exception("Could not ping global ctrl_iface after group removal")
  101. def test_p2p_device_concurrent_scan(dev, apdev):
  102. """Concurrent P2P and station mode scans with driver using cfg80211 P2P Device"""
  103. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  104. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  105. wpas.interface_add(iface)
  106. wpas.p2p_find()
  107. time.sleep(0.1)
  108. wpas.request("SCAN")
  109. ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  110. if ev is None:
  111. raise Exception("Station mode scan did not start")
  112. def test_p2p_device_nfc_invite(dev, apdev):
  113. """P2P NFC invitation with driver using cfg80211 P2P Device"""
  114. run_p2p_device_nfc_invite(dev, apdev, 0)
  115. def test_p2p_device_nfc_invite_no_group_iface(dev, apdev):
  116. """P2P NFC invitation with driver using cfg80211 P2P Device (no separate group interface)"""
  117. run_p2p_device_nfc_invite(dev, apdev, 1)
  118. def run_p2p_device_nfc_invite(dev, apdev, no_group_iface):
  119. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  120. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  121. wpas.interface_add(iface)
  122. wpas.global_request("SET p2p_no_group_iface %d" % no_group_iface)
  123. set_ip_addr_info(dev[0])
  124. logger.info("Start autonomous GO")
  125. dev[0].p2p_start_go()
  126. logger.info("Write NFC Tag on the P2P Client")
  127. res = wpas.global_request("P2P_LISTEN")
  128. if "FAIL" in res:
  129. raise Exception("Failed to start Listen mode")
  130. wpas.dump_monitor()
  131. pw = wpas.global_request("WPS_NFC_TOKEN NDEF").rstrip()
  132. if "FAIL" in pw:
  133. raise Exception("Failed to generate password token")
  134. res = wpas.global_request("P2P_SET nfc_tag 1").rstrip()
  135. if "FAIL" in res:
  136. raise Exception("Failed to enable NFC Tag for P2P static handover")
  137. sel = wpas.global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
  138. if "FAIL" in sel:
  139. raise Exception("Failed to generate NFC connection handover select")
  140. wpas.dump_monitor()
  141. logger.info("Read NFC Tag on the GO to trigger invitation")
  142. res = dev[0].global_request("WPS_NFC_TAG_READ " + sel)
  143. if "FAIL" in res:
  144. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  145. ev = wpas.wait_global_event(grpform_events, timeout=20)
  146. if ev is None:
  147. raise Exception("Joining the group timed out")
  148. res = wpas.group_form_result(ev)
  149. wpas.dump_monitor()
  150. hwsim_utils.test_connectivity_p2p(dev[0], wpas)
  151. check_ip_addr(res)
  152. wpas.dump_monitor()
  153. def test_p2p_device_misuses(dev, apdev):
  154. """cfg80211 P2P Device misuses"""
  155. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  156. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  157. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  158. wpas.interface_add(iface)
  159. # Add a normal network profile to the P2P Device management only
  160. # interface to verify that it does not get used.
  161. id = int(wpas.global_request('IFNAME=p2p-dev-%s ADD_NETWORK' % iface).strip())
  162. wpas.global_request('IFNAME=p2p-dev-%s SET_NETWORK %d ssid "open"' % (iface, id))
  163. wpas.global_request('IFNAME=p2p-dev-%s SET_NETWORK %d key_mgmt NONE' % (iface, id))
  164. wpas.global_request('IFNAME=p2p-dev-%s ENABLE_NETWORK %d' % (iface, id))
  165. # Scan requests get ignored on p2p-dev
  166. wpas.global_request('IFNAME=p2p-dev-%s SCAN' % iface)
  167. dev[0].p2p_start_go(freq=2412)
  168. addr = dev[0].p2p_interface_addr()
  169. wpas.scan_for_bss(addr, freq=2412)
  170. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  171. hwsim_utils.test_connectivity(wpas, hapd)
  172. pin = wpas.wps_read_pin()
  173. dev[0].p2p_go_authorize_client(pin)
  174. res = wpas.p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
  175. social=True, freq=2412)
  176. hwsim_utils.test_connectivity_p2p(dev[0], wpas)
  177. # Optimize scan-after-disconnect
  178. wpas.group_request("SET_NETWORK 0 scan_freq 2412")
  179. dev[0].group_request("DISASSOCIATE " + wpas.p2p_interface_addr())
  180. ev = wpas.wait_group_event(["CTRL-EVENT-DISCONNECT"])
  181. if ev is None:
  182. raise Exception("Did not see disconnect event on P2P group interface")
  183. dev[0].remove_group()
  184. ev = wpas.wait_group_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  185. if ev is None:
  186. raise Exception("Scan not started")
  187. ev = wpas.wait_group_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=15)
  188. if ev is None:
  189. raise Exception("Scan not completed")
  190. time.sleep(1)
  191. hwsim_utils.test_connectivity(wpas, hapd)
  192. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=0.1)
  193. if ev is not None:
  194. raise Exception("Unexpected disconnection event received from hostapd")
  195. ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.1)
  196. if ev is not None:
  197. raise Exception("Unexpected disconnection event received from wpa_supplicant")
  198. wpas.request("DISCONNECT")
  199. wpas.wait_disconnected()
  200. def test_p2p_device_incorrect_command_interface(dev, apdev):
  201. """cfg80211 P2P Device and P2P_* command on incorrect interface"""
  202. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  203. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  204. wpas.interface_add(iface)
  205. dev[0].p2p_listen()
  206. wpas.request('P2P_FIND type=social')
  207. ev = wpas.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  208. if ev is None:
  209. raise Exception("Peer not found")
  210. ev = wpas.wait_event(["P2P-DEVICE-FOUND"], timeout=0.1)
  211. if ev is not None:
  212. raise Exception("Unexpected P2P-DEVICE-FOUND event on station interface")
  213. wpas.dump_monitor()
  214. pin = wpas.wps_read_pin()
  215. dev[0].p2p_go_neg_auth(wpas.p2p_dev_addr(), pin, "enter", go_intent=14,
  216. freq=2412)
  217. wpas.request('P2P_STOP_FIND')
  218. wpas.dump_monitor()
  219. if "OK" not in wpas.request('P2P_CONNECT ' + dev[0].p2p_dev_addr() + ' ' + pin + ' display go_intent=1'):
  220. raise Exception("P2P_CONNECT failed")
  221. ev = wpas.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  222. if ev is None:
  223. raise Exception("Group formation timed out")
  224. wpas.group_form_result(ev)
  225. wpas.dump_monitor()
  226. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  227. if ev is None:
  228. raise Exception("Group formation timed out(2)")
  229. dev[0].group_form_result(ev)
  230. dev[0].remove_group()
  231. wpas.wait_go_ending_session()
  232. wpas.dump_monitor()
  233. def test_p2p_device_incorrect_command_interface2(dev, apdev):
  234. """cfg80211 P2P Device and P2P_GROUP_ADD command on incorrect interface"""
  235. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  236. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  237. wpas.interface_add(iface)
  238. if "OK" not in wpas.request('P2P_GROUP_ADD'):
  239. raise Exception("P2P_GROUP_ADD failed")
  240. ev = wpas.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  241. if ev is None:
  242. raise Exception("Group formation timed out")
  243. res = wpas.group_form_result(ev)
  244. wpas.dump_monitor()
  245. logger.info("Group results: " + str(res))
  246. wpas.remove_group()
  247. if not res['ifname'].startswith('p2p-' + iface + '-'):
  248. raise Exception("Unexpected group ifname: " + res['ifname'])
  249. wpas.dump_monitor()
  250. def test_p2p_device_grpform_timeout_client(dev, apdev):
  251. """P2P group formation timeout on client with cfg80211 P2P Device"""
  252. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  253. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  254. wpas.interface_add(iface)
  255. addr0 = dev[0].p2p_dev_addr()
  256. addr5 = wpas.p2p_dev_addr()
  257. wpas.p2p_listen()
  258. dev[0].discover_peer(addr5)
  259. dev[0].p2p_listen()
  260. wpas.discover_peer(addr0)
  261. wpas.p2p_ext_listen(100, 150)
  262. dev[0].global_request("P2P_CONNECT " + addr5 + " 12345670 enter go_intent=15 auth")
  263. wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=0")
  264. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=5)
  265. if ev is None:
  266. raise Exception("GO Negotiation did not succeed")
  267. ev = dev[0].wait_global_event(["WPS-SUCCESS"], timeout=10)
  268. if ev is None:
  269. raise Exception("WPS did not succeed (GO)")
  270. if "OK" not in dev[0].global_request("P2P_CANCEL"):
  271. wpas.global_request("P2P_CANCEL")
  272. del wpas
  273. raise HwsimSkip("Did not manage to cancel group formation")
  274. dev[0].dump_monitor()
  275. ev = wpas.wait_global_event(["WPS-SUCCESS"], timeout=10)
  276. if ev is None:
  277. raise Exception("WPS did not succeed (Client)")
  278. dev[0].dump_monitor()
  279. ev = wpas.wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=20)
  280. if ev is None:
  281. raise Exception("Group formation timeout not seen on client")
  282. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
  283. if ev is None:
  284. raise Exception("Group removal not seen on client")
  285. wpas.p2p_cancel_ext_listen()
  286. time.sleep(0.1)
  287. ifaces = wpas.global_request("INTERFACES")
  288. logger.info("Remaining interfaces: " + ifaces)
  289. del wpas
  290. if "p2p-" + iface + "-" in ifaces:
  291. raise Exception("Group interface still present after failure")
  292. def test_p2p_device_grpform_timeout_go(dev, apdev):
  293. """P2P group formation timeout on GO with cfg80211 P2P Device"""
  294. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  295. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  296. wpas.interface_add(iface)
  297. addr0 = dev[0].p2p_dev_addr()
  298. addr5 = wpas.p2p_dev_addr()
  299. wpas.p2p_listen()
  300. dev[0].discover_peer(addr5)
  301. dev[0].p2p_listen()
  302. wpas.discover_peer(addr0)
  303. wpas.p2p_ext_listen(100, 150)
  304. dev[0].global_request("P2P_CONNECT " + addr5 + " 12345670 enter go_intent=0 auth")
  305. wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=15")
  306. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=5)
  307. if ev is None:
  308. raise Exception("GO Negotiation did not succeed")
  309. ev = dev[0].wait_global_event(["WPS-SUCCESS"], timeout=10)
  310. if ev is None:
  311. raise Exception("WPS did not succeed (Client)")
  312. if "OK" not in dev[0].global_request("P2P_CANCEL"):
  313. if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE *"):
  314. wpas.global_request("P2P_CANCEL")
  315. del wpas
  316. raise HwsimSkip("Did not manage to cancel group formation")
  317. dev[0].dump_monitor()
  318. ev = wpas.wait_global_event(["WPS-SUCCESS"], timeout=10)
  319. if ev is None:
  320. raise Exception("WPS did not succeed (GO)")
  321. dev[0].dump_monitor()
  322. ev = wpas.wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=20)
  323. if ev is None:
  324. raise Exception("Group formation timeout not seen on GO")
  325. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
  326. if ev is None:
  327. raise Exception("Group removal not seen on GO")
  328. wpas.p2p_cancel_ext_listen()
  329. time.sleep(0.1)
  330. ifaces = wpas.global_request("INTERFACES")
  331. logger.info("Remaining interfaces: " + ifaces)
  332. del wpas
  333. if "p2p-" + iface + "-" in ifaces:
  334. raise Exception("Group interface still present after failure")
  335. def test_p2p_device_autogo(dev, apdev):
  336. """P2P autogo using cfg80211 P2P Device"""
  337. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  338. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  339. wpas.interface_add(iface)
  340. res = wpas.p2p_start_go()
  341. if not res['ifname'].startswith('p2p-' + iface):
  342. raise Exception("Unexpected group ifname: " + res['ifname'])
  343. bssid = wpas.get_group_status_field('bssid')
  344. dev[0].scan_for_bss(bssid, res['freq'])
  345. connect_cli(wpas, dev[0], freq=res['freq'])
  346. terminate_group(wpas, dev[0])
  347. def test_p2p_device_autogo_no_group_iface(dev, apdev):
  348. """P2P autogo using cfg80211 P2P Device (no separate group interface)"""
  349. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  350. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  351. wpas.interface_add(iface)
  352. wpas.global_request("SET p2p_no_group_iface 1")
  353. res = wpas.p2p_start_go()
  354. if res['ifname'] != iface:
  355. raise Exception("Unexpected group ifname: " + res['ifname'])
  356. bssid = wpas.get_group_status_field('bssid')
  357. dev[0].scan_for_bss(bssid, res['freq'])
  358. connect_cli(wpas, dev[0], freq=res['freq'])
  359. terminate_group(wpas, dev[0])
  360. def test_p2p_device_join(dev, apdev):
  361. """P2P join-group using cfg80211 P2P Device"""
  362. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  363. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  364. wpas.interface_add(iface)
  365. res = dev[0].p2p_start_go()
  366. bssid = dev[0].get_group_status_field('bssid')
  367. wpas.scan_for_bss(bssid, res['freq'])
  368. res2 = connect_cli(dev[0], wpas, freq=res['freq'])
  369. if not res2['ifname'].startswith('p2p-' + iface):
  370. raise Exception("Unexpected group ifname: " + res2['ifname'])
  371. terminate_group(dev[0], wpas)
  372. def test_p2p_device_join_no_group_iface(dev, apdev):
  373. """P2P join-group using cfg80211 P2P Device (no separate group interface)"""
  374. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  375. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  376. wpas.interface_add(iface)
  377. wpas.global_request("SET p2p_no_group_iface 1")
  378. res = dev[0].p2p_start_go()
  379. bssid = dev[0].get_group_status_field('bssid')
  380. wpas.scan_for_bss(bssid, res['freq'])
  381. res2 = connect_cli(dev[0], wpas, freq=res['freq'])
  382. if res2['ifname'] != iface:
  383. raise Exception("Unexpected group ifname: " + res2['ifname'])
  384. terminate_group(dev[0], wpas)
  385. def test_p2p_device_persistent_group(dev):
  386. """P2P persistent group formation and re-invocation with cfg80211 P2P Device"""
  387. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  388. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  389. wpas.interface_add(iface)
  390. wpas.global_request("SET p2p_no_group_iface 0")
  391. form(dev[0], wpas)
  392. invite_from_cli(dev[0], wpas)
  393. invite_from_go(dev[0], wpas)
  394. def test_p2p_device_persistent_group_no_group_iface(dev):
  395. """P2P persistent group formation and re-invocation with cfg80211 P2P Device (no separate group interface)"""
  396. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  397. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  398. wpas.interface_add(iface)
  399. wpas.global_request("SET p2p_no_group_iface 1")
  400. form(dev[0], wpas)
  401. invite_from_cli(dev[0], wpas)
  402. invite_from_go(dev[0], wpas)
  403. def test_p2p_device_persistent_group2(dev):
  404. """P2P persistent group formation and re-invocation (reverse) with cfg80211 P2P Device"""
  405. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  406. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  407. wpas.interface_add(iface)
  408. wpas.global_request("SET p2p_no_group_iface 0")
  409. form(wpas, dev[0])
  410. invite_from_cli(wpas, dev[0])
  411. invite_from_go(wpas, dev[0])
  412. def test_p2p_device_persistent_group2_no_group_iface(dev):
  413. """P2P persistent group formation and re-invocation (reverse) with cfg80211 P2P Device (no separate group interface)"""
  414. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  415. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  416. wpas.interface_add(iface)
  417. wpas.global_request("SET p2p_no_group_iface 1")
  418. form(wpas, dev[0])
  419. invite_from_cli(wpas, dev[0])
  420. invite_from_go(wpas, dev[0])
  421. def p2p_device_group_conf(dev1, dev2):
  422. dev1.global_request("SET p2p_group_idle 12")
  423. dev1.global_request("SET p2p_go_freq_change_policy 2")
  424. dev1.global_request("SET p2p_go_ctwindow 7")
  425. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev1, i_intent=15,
  426. r_dev=dev2, r_intent=0)
  427. check_grpform_results(i_res, r_res)
  428. if (dev1.group_request("GET p2p_group_idle") != "12" or
  429. dev1.group_request("GET p2p_go_freq_change_policy") != "2" or
  430. dev1.group_request("GET p2p_go_ctwindow") != "7"):
  431. raise Exception("Unexpected configuration value")
  432. remove_group(dev1, dev2)
  433. dev1.global_request("P2P_FLUSH")
  434. dev2.global_request("P2P_FLUSH")
  435. def test_p2p_device_conf(dev, apdev):
  436. """P2P configuration with cfg80211 P2P Device"""
  437. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  438. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  439. wpas.interface_add(iface)
  440. wpas.global_request("SET p2p_no_group_iface 1")
  441. p2p_device_group_conf(wpas, dev[0])
  442. wpas.global_request("SET p2p_no_group_iface 0")
  443. p2p_device_group_conf(wpas, dev[0])
  444. def test_p2p_device_autogo_chan_switch(dev):
  445. """P2P autonomous GO switching channels with cfg80211 P2P Device"""
  446. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  447. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  448. wpas.interface_add(iface)
  449. wpas.global_request("SET p2p_no_group_iface 1")
  450. autogo(wpas, freq=2417)
  451. connect_cli(wpas, dev[1])
  452. res = wpas.group_request("CHAN_SWITCH 5 2422")
  453. if "FAIL" in res:
  454. # for now, skip test since mac80211_hwsim support is not yet widely
  455. # deployed
  456. raise HwsimSkip("Assume mac80211_hwsim did not support channel switching")
  457. ev = wpas.wait_group_event(["AP-CSA-FINISHED"], timeout=10)
  458. if ev is None:
  459. raise Exception("CSA finished event timed out")
  460. if "freq=2422" not in ev:
  461. raise Exception("Unexpected cahnnel in CSA finished event")
  462. wpas.dump_monitor()
  463. dev[1].dump_monitor()
  464. time.sleep(0.1)
  465. hwsim_utils.test_connectivity_p2p(wpas, dev[1])