test_p2p_set.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # P2P_SET test cases
  2. # Copyright (c) 2014, 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. def test_p2p_set(dev):
  8. """P2P_SET commands"""
  9. for cmd in [ "",
  10. "foo bar",
  11. "noa 1",
  12. "noa 1,2",
  13. "noa 1,2,3",
  14. "noa -1,0,0",
  15. "noa 256,0,0",
  16. "noa 0,-1,0",
  17. "noa 0,0,-1",
  18. "noa 0,0,1",
  19. "noa 255,10,20",
  20. "ps 1",
  21. "ps 2",
  22. "oppps 1",
  23. "ctwindow 1",
  24. "conc_pref foo",
  25. "peer_filter foo",
  26. "client_apsd 0",
  27. "client_apsd 0,0",
  28. "client_apsd 0,0,0",
  29. "disc_int 1",
  30. "disc_int 1 2",
  31. "disc_int 2 1 10",
  32. "disc_int -1 0 10",
  33. "disc_int 0 -1 10",
  34. "ssid_postfix 123456789012345678901234" ]:
  35. if "FAIL" not in dev[0].request("P2P_SET " + cmd):
  36. raise Exception("Invalid P2P_SET accepted: " + cmd)
  37. def test_p2p_set_discoverability(dev):
  38. """P2P_SET discoverability"""
  39. addr0 = dev[0].p2p_dev_addr()
  40. addr1 = dev[1].p2p_dev_addr()
  41. dev[0].p2p_start_go(freq="2412")
  42. if "OK" not in dev[1].request("P2P_SET discoverability 0"):
  43. raise Exception("P2P_SET discoverability 0 failed")
  44. pin = dev[1].wps_read_pin()
  45. dev[0].p2p_go_authorize_client(pin)
  46. dev[1].p2p_connect_group(addr0, pin, timeout=20, social=True, freq="2412")
  47. if not dev[2].discover_peer(addr1, timeout=10):
  48. if not dev[2].discover_peer(addr1, timeout=10):
  49. if not dev[2].discover_peer(addr1, timeout=10):
  50. raise Exception("Could not discover group client")
  51. peer = dev[2].get_peer(addr1)
  52. if int(peer['dev_capab'], 16) & 0x02 != 0:
  53. raise Exception("Discoverability dev_capab reported: " + peer['dev_capab'])
  54. dev[2].p2p_stop_find()
  55. if "OK" not in dev[1].request("P2P_SET discoverability 1"):
  56. raise Exception("P2P_SET discoverability 1 failed")
  57. dev[1].dump_monitor()
  58. dev[1].group_request("REASSOCIATE")
  59. ev = dev[1].wait_group_event(["CTRL-EVENT-CONNECTED"], timeout=20)
  60. if ev is None:
  61. raise Exception("Connection timed out")
  62. dev[2].request("P2P_FLUSH")
  63. if not dev[2].discover_peer(addr1, timeout=10):
  64. if not dev[2].discover_peer(addr1, timeout=10):
  65. if not dev[2].discover_peer(addr1, timeout=10):
  66. raise Exception("Could not discover group client")
  67. peer = dev[2].get_peer(addr1)
  68. if int(peer['dev_capab'], 16) & 0x02 != 0x02:
  69. raise Exception("Discoverability dev_capab reported: " + peer['dev_capab'])
  70. dev[2].p2p_stop_find()
  71. def test_p2p_set_managed(dev):
  72. """P2P_SET managed"""
  73. addr0 = dev[0].p2p_dev_addr()
  74. if "OK" not in dev[0].request("P2P_SET managed 1"):
  75. raise Exception("P2P_SET managed 1 failed")
  76. dev[0].p2p_listen()
  77. if not dev[1].discover_peer(addr0):
  78. raise Exception("Could not discover peer")
  79. peer = dev[1].get_peer(addr0)
  80. if int(peer['dev_capab'], 16) & 0x08 != 0x08:
  81. raise Exception("Managed dev_capab not reported: " + peer['dev_capab'])
  82. dev[1].p2p_stop_find()
  83. if "OK" not in dev[0].request("P2P_SET managed 0"):
  84. raise Exception("P2P_SET managed 0 failed")
  85. if not dev[2].discover_peer(addr0):
  86. raise Exception("Could not discover peer")
  87. peer = dev[2].get_peer(addr0)
  88. if int(peer['dev_capab'], 16) & 0x08 != 0:
  89. raise Exception("Managed dev_capab reported: " + peer['dev_capab'])
  90. dev[2].p2p_stop_find()
  91. dev[0].p2p_stop_find()
  92. @remote_compatible
  93. def test_p2p_set_ssid_postfix(dev):
  94. """P2P_SET ssid_postfix"""
  95. addr0 = dev[0].p2p_dev_addr()
  96. addr1 = dev[1].p2p_dev_addr()
  97. postfix = "12345678901234567890123"
  98. try:
  99. if "OK" not in dev[0].request("P2P_SET ssid_postfix " + postfix):
  100. raise Exception("P2P_SET ssid_postfix failed")
  101. dev[0].p2p_start_go(freq="2412")
  102. pin = dev[1].wps_read_pin()
  103. dev[0].p2p_go_authorize_client(pin)
  104. dev[1].p2p_connect_group(addr0, pin, timeout=20, social=True, freq="2412")
  105. if postfix not in dev[1].get_group_status_field("ssid"):
  106. raise Exception("SSID postfix missing from status")
  107. if postfix not in dev[1].group_request("SCAN_RESULTS"):
  108. raise Exception("SSID postfix missing from scan results")
  109. finally:
  110. dev[0].request("P2P_SET ssid_postfix ")