test_p2p_invitation.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # P2P invitation test cases
  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 hwsim_utils
  9. def test_p2p_go_invite(dev):
  10. """P2P GO inviting a client to join"""
  11. addr0 = dev[0].p2p_dev_addr()
  12. addr1 = dev[1].p2p_dev_addr()
  13. logger.info("Generate BSS table entry for old group")
  14. # this adds more coverage to testing by forcing the GO to be found with an
  15. # older entry in the BSS table and with that entry having a different
  16. # operating channel.
  17. dev[0].p2p_start_go(freq=2422)
  18. dev[1].scan()
  19. dev[0].remove_group()
  20. logger.info("Discover peer")
  21. dev[1].p2p_listen()
  22. if not dev[0].discover_peer(addr1, social=True):
  23. raise Exception("Peer " + addr1 + " not found")
  24. logger.info("Start GO on non-social channel")
  25. res = dev[0].p2p_start_go(freq=2417)
  26. logger.debug("res: " + str(res))
  27. logger.info("Invite peer to join the group")
  28. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  29. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
  30. if ev is None:
  31. raise Exception("Timeout on invitation on peer")
  32. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  33. if ev is None:
  34. raise Exception("Timeout on invitation on GO")
  35. if "status=1" not in ev:
  36. raise Exception("Unexpected invitation result")
  37. logger.info("Join the group")
  38. pin = dev[1].wps_read_pin()
  39. dev[0].p2p_go_authorize_client(pin)
  40. dev[1].p2p_connect_group(addr0, pin, timeout=60)
  41. logger.info("Client connected")
  42. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  43. logger.info("Terminate group")
  44. dev[0].remove_group()
  45. dev[1].wait_go_ending_session()
  46. def test_p2p_go_invite_auth(dev):
  47. """P2P GO inviting a client to join (authorized invitation)"""
  48. addr0 = dev[0].p2p_dev_addr()
  49. addr1 = dev[1].p2p_dev_addr()
  50. logger.info("Generate BSS table entry for old group")
  51. # this adds more coverage to testing by forcing the GO to be found with an
  52. # older entry in the BSS table and with that entry having a different
  53. # operating channel.
  54. dev[0].p2p_start_go(freq=2432)
  55. dev[1].scan()
  56. dev[0].remove_group()
  57. dev[0].dump_monitor()
  58. dev[1].dump_monitor()
  59. logger.info("Discover peer")
  60. dev[1].p2p_listen()
  61. if not dev[0].discover_peer(addr1, social=True):
  62. raise Exception("Peer " + addr1 + " not found")
  63. dev[0].p2p_listen()
  64. if not dev[1].discover_peer(addr0, social=True):
  65. raise Exception("Peer " + addr0 + " not found")
  66. dev[1].p2p_listen()
  67. logger.info("Authorize invitation")
  68. pin = dev[1].wps_read_pin()
  69. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  70. logger.info("Start GO on non-social channel")
  71. res = dev[0].p2p_start_go(freq=2427)
  72. logger.debug("res: " + str(res))
  73. logger.info("Invite peer to join the group")
  74. dev[0].p2p_go_authorize_client(pin)
  75. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  76. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  77. "P2P-GROUP-STARTED"], timeout=20)
  78. if ev is None:
  79. raise Exception("Timeout on invitation on peer")
  80. if "P2P-INVITATION-RECEIVED" in ev:
  81. raise Exception("Unexpected request to accept pre-authorized invitaton")
  82. dev[0].dump_monitor()
  83. logger.info("Client connected")
  84. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  85. logger.info("Terminate group")
  86. dev[0].remove_group()
  87. dev[1].wait_go_ending_session()