test_p2p_set.py 4.5 KB

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