test_p2p_invitation.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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()
  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()
  48. def test_p2p_go_invite_auth(dev):
  49. """P2P GO inviting a client to join (authorized invitation)"""
  50. addr0 = dev[0].p2p_dev_addr()
  51. addr1 = dev[1].p2p_dev_addr()
  52. logger.info("Generate BSS table entry for old group")
  53. # this adds more coverage to testing by forcing the GO to be found with an
  54. # older entry in the BSS table and with that entry having a different
  55. # operating channel.
  56. dev[0].p2p_start_go(freq=2432)
  57. dev[1].scan()
  58. dev[0].remove_group()
  59. dev[0].dump_monitor()
  60. dev[1].dump_monitor()
  61. logger.info("Discover peer")
  62. dev[1].p2p_listen()
  63. if not dev[0].discover_peer(addr1, social=True):
  64. raise Exception("Peer " + addr1 + " not found")
  65. dev[0].p2p_listen()
  66. if not dev[1].discover_peer(addr0, social=True):
  67. raise Exception("Peer " + addr0 + " not found")
  68. dev[1].p2p_listen()
  69. logger.info("Authorize invitation")
  70. pin = dev[1].wps_read_pin()
  71. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  72. logger.info("Start GO on non-social channel")
  73. res = dev[0].p2p_start_go(freq=2427)
  74. logger.debug("res: " + str(res))
  75. logger.info("Invite peer to join the group")
  76. dev[0].p2p_go_authorize_client(pin)
  77. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  78. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  79. "P2P-GROUP-STARTED"], timeout=20)
  80. if ev is None:
  81. raise Exception("Timeout on invitation on peer")
  82. if "P2P-INVITATION-RECEIVED" in ev:
  83. raise Exception("Unexpected request to accept pre-authorized invitaton")
  84. dev[0].dump_monitor()
  85. logger.info("Client connected")
  86. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  87. logger.info("Terminate group")
  88. dev[0].remove_group()
  89. dev[1].wait_go_ending_session()