test_p2p_invitation.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python
  2. #
  3. # P2P invitation test cases
  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 logging
  9. logger = logging.getLogger(__name__)
  10. import hwsim_utils
  11. def test_p2p_go_invite(dev):
  12. """P2P GO inviting a client to join"""
  13. addr0 = dev[0].p2p_dev_addr()
  14. addr1 = dev[1].p2p_dev_addr()
  15. logger.info("Discover peer")
  16. dev[1].p2p_listen()
  17. if not dev[0].discover_peer(addr1, social=True):
  18. raise Exception("Peer " + addr1 + " not found")
  19. logger.info("Start GO on non-social channel")
  20. res = dev[0].p2p_start_go(freq=2417)
  21. logger.debug("res: " + str(res))
  22. logger.info("Invite peer to join the group")
  23. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  24. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
  25. if ev is None:
  26. raise Exception("Timeout on invitation on peer")
  27. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  28. if ev is None:
  29. raise Exception("Timeout on invitation on GO")
  30. if "status=1" not in ev:
  31. raise Exception("Unexpected invitation result")
  32. logger.info("Join the group")
  33. pin = dev[1].wps_read_pin()
  34. dev[0].p2p_go_authorize_client(pin)
  35. dev[1].p2p_connect_group(addr0, pin, timeout=60)
  36. logger.info("Client connected")
  37. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  38. logger.info("Terminate group")
  39. dev[0].remove_group()
  40. dev[1].wait_go_ending_session()