p2p-group-formation.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/python
  2. #
  3. # P2P group formation test
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import os
  9. import sys
  10. import time
  11. import subprocess
  12. import logging
  13. from wpasupplicant import WpaSupplicant
  14. def test_connectivity(ifname1, ifname2):
  15. cmd = ["sudo",
  16. "../../mac80211_hwsim/tools/hwsim_test",
  17. ifname1,
  18. ifname2]
  19. subprocess.check_call(cmd)
  20. def main():
  21. if len(sys.argv) > 1 and sys.argv[1] == '-d':
  22. logging.basicConfig(level=logging.DEBUG)
  23. else:
  24. logging.basicConfig()
  25. dev0 = WpaSupplicant('wlan0')
  26. dev1 = WpaSupplicant('wlan1')
  27. dev0.request("hello")
  28. dev0.ping()
  29. if not dev0.ping() or not dev1.ping():
  30. print "No response from wpa_supplicant"
  31. return
  32. addr0 = dev0.p2p_dev_addr()
  33. addr1 = dev1.p2p_dev_addr()
  34. print "dev0 P2P Device Address: " + addr0
  35. print "dev1 P2P Device Address: " + addr1
  36. dev0.reset()
  37. dev1.reset()
  38. dev0.p2p_listen()
  39. dev1.p2p_listen()
  40. pin = dev0.wps_read_pin()
  41. dev0.p2p_go_neg_auth(addr1, pin, "display")
  42. print "Start GO negotiation"
  43. dev1.p2p_go_neg_init(addr0, pin, "enter", timeout=15)
  44. dev0.dump_monitor()
  45. dev1.dump_monitor()
  46. print "Group formed"
  47. test_connectivity('wlan0', 'wlan1')
  48. dev0.remove_group('wlan0')
  49. try:
  50. dev1.remove_group('wlan1')
  51. except:
  52. pass
  53. print "Test passed"
  54. if __name__ == "__main__":
  55. main()