test_p2p_set.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. dev[1].wait_connected(timeout=20)
  59. dev[2].request("P2P_FLUSH")
  60. if not dev[2].discover_peer(addr1, timeout=10):
  61. if not dev[2].discover_peer(addr1, timeout=10):
  62. if not dev[2].discover_peer(addr1, timeout=10):
  63. raise Exception("Could not discover group client")
  64. peer = dev[2].get_peer(addr1)
  65. if int(peer['dev_capab'], 16) & 0x02 != 0x02:
  66. raise Exception("Discoverability dev_capab reported: " + peer['dev_capab'])
  67. dev[2].p2p_stop_find()
  68. def test_p2p_set_managed(dev):
  69. """P2P_SET managed"""
  70. addr0 = dev[0].p2p_dev_addr()
  71. if "OK" not in dev[0].request("P2P_SET managed 1"):
  72. raise Exception("P2P_SET managed 1 failed")
  73. dev[0].p2p_listen()
  74. if not dev[1].discover_peer(addr0):
  75. raise Exception("Could not discover peer")
  76. peer = dev[1].get_peer(addr0)
  77. if int(peer['dev_capab'], 16) & 0x08 != 0x08:
  78. raise Exception("Managed dev_capab not reported: " + peer['dev_capab'])
  79. dev[1].p2p_stop_find()
  80. if "OK" not in dev[0].request("P2P_SET managed 0"):
  81. raise Exception("P2P_SET managed 0 failed")
  82. if not dev[2].discover_peer(addr0):
  83. raise Exception("Could not discover peer")
  84. peer = dev[2].get_peer(addr0)
  85. if int(peer['dev_capab'], 16) & 0x08 != 0:
  86. raise Exception("Managed dev_capab reported: " + peer['dev_capab'])
  87. dev[2].p2p_stop_find()
  88. dev[0].p2p_stop_find()
  89. def test_p2p_set_ssid_postfix(dev):
  90. """P2P_SET ssid_postfix"""
  91. addr0 = dev[0].p2p_dev_addr()
  92. addr1 = dev[1].p2p_dev_addr()
  93. postfix = "12345678901234567890123"
  94. try:
  95. if "OK" not in dev[0].request("P2P_SET ssid_postfix " + postfix):
  96. raise Exception("P2P_SET ssid_postfix failed")
  97. dev[0].p2p_start_go(freq="2412")
  98. pin = dev[1].wps_read_pin()
  99. dev[0].p2p_go_authorize_client(pin)
  100. dev[1].p2p_connect_group(addr0, pin, timeout=20, social=True, freq="2412")
  101. if postfix not in dev[1].get_status_field("ssid"):
  102. raise Exception("SSID postfix missing from status")
  103. if postfix not in dev[1].request("SCAN_RESULTS"):
  104. raise Exception("SSID postfix missing from scan results")
  105. finally:
  106. dev[0].request("P2P_SET ssid_postfix ")