test_p2p_invitation.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import hwsim_utils
  10. @remote_compatible
  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. @remote_compatible
  49. def test_p2p_go_invite_auth(dev):
  50. """P2P GO inviting a client to join (authorized invitation)"""
  51. addr0 = dev[0].p2p_dev_addr()
  52. addr1 = dev[1].p2p_dev_addr()
  53. logger.info("Generate BSS table entry for old group")
  54. # this adds more coverage to testing by forcing the GO to be found with an
  55. # older entry in the BSS table and with that entry having a different
  56. # operating channel.
  57. dev[0].p2p_start_go(freq=2432)
  58. dev[1].scan()
  59. dev[0].remove_group()
  60. dev[0].dump_monitor()
  61. dev[1].dump_monitor()
  62. logger.info("Discover peer")
  63. dev[1].p2p_listen()
  64. if not dev[0].discover_peer(addr1, social=True):
  65. raise Exception("Peer " + addr1 + " not found")
  66. dev[0].p2p_listen()
  67. if not dev[1].discover_peer(addr0, social=True):
  68. raise Exception("Peer " + addr0 + " not found")
  69. dev[1].p2p_listen()
  70. logger.info("Authorize invitation")
  71. pin = dev[1].wps_read_pin()
  72. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  73. logger.info("Start GO on non-social channel")
  74. res = dev[0].p2p_start_go(freq=2427)
  75. logger.debug("res: " + str(res))
  76. logger.info("Invite peer to join the group")
  77. dev[0].p2p_go_authorize_client(pin)
  78. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  79. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  80. "P2P-GROUP-STARTED"], timeout=20)
  81. if ev is None:
  82. raise Exception("Timeout on invitation on peer")
  83. if "P2P-INVITATION-RECEIVED" in ev:
  84. raise Exception("Unexpected request to accept pre-authorized invitaton")
  85. dev[1].group_form_result(ev)
  86. dev[0].dump_monitor()
  87. logger.info("Client connected")
  88. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  89. logger.info("Terminate group")
  90. dev[0].remove_group()
  91. dev[1].wait_go_ending_session()
  92. @remote_compatible
  93. def test_p2p_go_invite_unknown(dev):
  94. """P2P GO inviting a client that has not discovered the GO"""
  95. try:
  96. addr0 = dev[0].p2p_dev_addr()
  97. addr1 = dev[1].p2p_dev_addr()
  98. dev[1].p2p_listen()
  99. if not dev[0].discover_peer(addr1, social=True):
  100. raise Exception("Peer " + addr1 + " not found")
  101. dev[1].global_request("P2P_FLUSH")
  102. dev[1].p2p_listen()
  103. dev[0].p2p_start_go(freq=2412)
  104. logger.info("Invite peer to join the group")
  105. # Prevent peer entry from being added for testing coverage
  106. if "OK" not in dev[1].global_request("P2P_SET peer_filter 00:11:22:33:44:55"):
  107. raise Exception("Failed to set peer_filter")
  108. dev[0].p2p_go_authorize_client("12345670")
  109. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  110. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
  111. if ev is None:
  112. raise Exception("Invitation Request not received")
  113. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  114. if ev is None:
  115. raise Exception("Invitation Response not received")
  116. if "status=1" not in ev:
  117. raise Exception("Unexpected invitation result: " + ev)
  118. finally:
  119. dev[1].global_request("P2P_SET peer_filter 00:00:00:00:00:00")
  120. def test_p2p_cli_invite(dev):
  121. """P2P Client inviting a device to join"""
  122. addr0 = dev[0].p2p_dev_addr()
  123. addr1 = dev[1].p2p_dev_addr()
  124. addr2 = dev[2].p2p_dev_addr()
  125. dev[0].p2p_start_go(freq=2412)
  126. pin = dev[1].wps_read_pin()
  127. dev[0].p2p_go_authorize_client(pin)
  128. dev[1].p2p_connect_group(addr0, pin, timeout=60)
  129. dev[2].p2p_listen()
  130. if not dev[1].discover_peer(addr2, social=True):
  131. raise Exception("Peer " + addr2 + " not found")
  132. if "OK" not in dev[1].global_request("P2P_INVITE group=" + dev[1].group_ifname + " peer=" + addr2):
  133. raise Exception("Unexpected failure of P2P_INVITE to known peer")
  134. ev = dev[2].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
  135. if ev is None:
  136. raise Exception("Timeout on invitation invited peer")
  137. if "sa=" + addr1 not in ev:
  138. raise Exception("Incorrect source address")
  139. if "go_dev_addr=" + addr0 not in ev:
  140. raise Exception("Incorrect GO address")
  141. ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  142. if ev is None:
  143. raise Exception("Timeout on invitation on inviting client")
  144. if "status=1" not in ev:
  145. raise Exception("Unexpected invitation result")
  146. pin = dev[2].wps_read_pin()
  147. dev[0].p2p_go_authorize_client(pin)
  148. dev[2].p2p_connect_group(addr0, pin, timeout=60)
  149. if "FAIL" not in dev[1].global_request("P2P_INVITE group=" + dev[1].group_ifname + " peer=00:11:22:33:44:55"):
  150. raise Exception("Unexpected success of P2P_INVITE to unknown peer")
  151. dev[0].remove_group()
  152. dev[1].wait_go_ending_session()
  153. dev[2].wait_go_ending_session()
  154. @remote_compatible
  155. def test_p2p_invite_invalid(dev):
  156. """Invalid parameters to P2P_INVITE"""
  157. id = dev[0].add_network()
  158. for cmd in [ "foo=bar",
  159. "persistent=123 peer=foo",
  160. "persistent=123",
  161. "persistent=%d" % id,
  162. "group=foo",
  163. "group=foo peer=foo",
  164. "group=foo peer=00:11:22:33:44:55 go_dev_addr=foo" ]:
  165. if "FAIL" not in dev[0].request("P2P_INVITE " + cmd):
  166. raise Exception("Invalid P2P_INVITE accepted: " + cmd)