test_p2p_invitation.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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("Generate BSS table entry for old group")
  16. # this adds more coverage to testing by forcing the GO to be found with an
  17. # older entry in the BSS table and with that entry having a different
  18. # operating channel.
  19. dev[0].p2p_start_go(freq=2422)
  20. dev[1].scan()
  21. dev[0].remove_group()
  22. logger.info("Discover peer")
  23. dev[1].p2p_listen()
  24. if not dev[0].discover_peer(addr1, social=True):
  25. raise Exception("Peer " + addr1 + " not found")
  26. logger.info("Start GO on non-social channel")
  27. res = dev[0].p2p_start_go(freq=2417)
  28. logger.debug("res: " + str(res))
  29. logger.info("Invite peer to join the group")
  30. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  31. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
  32. if ev is None:
  33. raise Exception("Timeout on invitation on peer")
  34. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  35. if ev is None:
  36. raise Exception("Timeout on invitation on GO")
  37. if "status=1" not in ev:
  38. raise Exception("Unexpected invitation result")
  39. logger.info("Join the group")
  40. pin = dev[1].wps_read_pin()
  41. dev[0].p2p_go_authorize_client(pin)
  42. dev[1].p2p_connect_group(addr0, pin, timeout=60)
  43. logger.info("Client connected")
  44. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  45. logger.info("Terminate group")
  46. dev[0].remove_group()
  47. dev[1].wait_go_ending_session()