test_p2p_device.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # cfg80211 P2P Device
  2. # Copyright (c) 2013, 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 test_p2p_grpform import go_neg_pin_authorized
  11. from test_p2p_grpform import check_grpform_results
  12. from test_p2p_grpform import remove_group
  13. from test_nfc_p2p import set_ip_addr_info, check_ip_addr, grpform_events
  14. from hwsim import HWSimRadio
  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. remove_group(dev[0], wpas)
  25. res = wpas.global_request("IFNAME=p2p-dev-" + iface + " STATUS-DRIVER")
  26. lines = res.splitlines()
  27. found = False
  28. for l in lines:
  29. try:
  30. [name,value] = l.split('=', 1)
  31. if name == "wdev_id":
  32. found = True
  33. break
  34. except ValueError:
  35. pass
  36. if not found:
  37. raise Exception("wdev_id not found")
  38. def test_p2p_device_grpform2(dev, apdev):
  39. """P2P group formation with driver using cfg80211 P2P Device (reverse)"""
  40. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  41. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  42. wpas.interface_add(iface)
  43. [i_res, r_res] = go_neg_pin_authorized(i_dev=wpas, i_intent=15,
  44. r_dev=dev[0], r_intent=0)
  45. check_grpform_results(i_res, r_res)
  46. remove_group(wpas, dev[0])
  47. def test_p2p_device_group_remove(dev, apdev):
  48. """P2P group removal via the P2P ctrl interface with driver using cfg80211 P2P Device"""
  49. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  50. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  51. wpas.interface_add(iface)
  52. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  53. r_dev=wpas, r_intent=0)
  54. check_grpform_results(i_res, r_res)
  55. # Issue the remove request on the interface which will be removed
  56. p2p_iface_wpas = WpaSupplicant(ifname=r_res['ifname'])
  57. res = p2p_iface_wpas.request("P2P_GROUP_REMOVE *")
  58. if "OK" not in res:
  59. raise Exception("Failed to remove P2P group")
  60. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  61. if ev is None:
  62. raise Exception("Group removal event not received")
  63. if not wpas.global_ping():
  64. raise Exception("Could not ping global ctrl_iface after group removal")
  65. def test_p2p_device_concurrent_scan(dev, apdev):
  66. """Concurrent P2P and station mode scans with driver using cfg80211 P2P Device"""
  67. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  68. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  69. wpas.interface_add(iface)
  70. wpas.p2p_find()
  71. time.sleep(0.1)
  72. wpas.request("SCAN")
  73. ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  74. if ev is None:
  75. raise Exception("Station mode scan did not start")
  76. def test_p2p_device_nfc_invite(dev, apdev):
  77. """P2P NFC invitiation with driver using cfg80211 P2P Device"""
  78. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  79. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  80. wpas.interface_add(iface)
  81. set_ip_addr_info(dev[0])
  82. logger.info("Start autonomous GO")
  83. dev[0].p2p_start_go()
  84. logger.info("Write NFC Tag on the P2P Client")
  85. res = wpas.global_request("P2P_LISTEN")
  86. if "FAIL" in res:
  87. raise Exception("Failed to start Listen mode")
  88. pw = wpas.global_request("WPS_NFC_TOKEN NDEF").rstrip()
  89. if "FAIL" in pw:
  90. raise Exception("Failed to generate password token")
  91. res = wpas.global_request("P2P_SET nfc_tag 1").rstrip()
  92. if "FAIL" in res:
  93. raise Exception("Failed to enable NFC Tag for P2P static handover")
  94. sel = wpas.global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
  95. if "FAIL" in sel:
  96. raise Exception("Failed to generate NFC connection handover select")
  97. logger.info("Read NFC Tag on the GO to trigger invitation")
  98. res = dev[0].request("WPS_NFC_TAG_READ " + sel)
  99. if "FAIL" in res:
  100. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  101. ev = wpas.wait_global_event(grpform_events, timeout=20)
  102. if ev is None:
  103. raise Exception("Joining the group timed out")
  104. res = wpas.group_form_result(ev)
  105. hwsim_utils.test_connectivity_p2p(dev[0], wpas)
  106. check_ip_addr(res)