test_wnm.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # WNM tests
  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 time
  7. import logging
  8. logger = logging.getLogger()
  9. import hostapd
  10. from wlantest import Wlantest
  11. def test_wnm_bss_transition_mgmt(dev, apdev):
  12. """WNM BSS Transition Management"""
  13. params = { "ssid": "test-wnm",
  14. "time_advertisement": "2",
  15. "time_zone": "EST5",
  16. "wnm_sleep_mode": "1",
  17. "bss_transition": "1" }
  18. hostapd.add_ap(apdev[0]['ifname'], params)
  19. dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
  20. dev[0].request("WNM_BSS_QUERY 0")
  21. def test_wnm_disassoc_imminent(dev, apdev):
  22. """WNM Disassociation Imminent"""
  23. params = { "ssid": "test-wnm",
  24. "time_advertisement": "2",
  25. "time_zone": "EST5",
  26. "wnm_sleep_mode": "1",
  27. "bss_transition": "1" }
  28. hostapd.add_ap(apdev[0]['ifname'], params)
  29. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  30. dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
  31. addr = dev[0].p2p_interface_addr()
  32. hapd.request("DISASSOC_IMMINENT " + addr + " 10")
  33. ev = dev[0].wait_event(["WNM: Disassociation Imminent"])
  34. if ev is None:
  35. raise Exception("Timeout while waiting for disassociation imminent")
  36. if "Disassociation Timer 10" not in ev:
  37. raise Exception("Unexpected disassociation imminent contents")
  38. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  39. if ev is None:
  40. raise Exception("Timeout while waiting for re-connection scan")
  41. def test_wnm_ess_disassoc_imminent(dev, apdev):
  42. """WNM ESS Disassociation Imminent"""
  43. params = { "ssid": "test-wnm",
  44. "time_advertisement": "2",
  45. "time_zone": "EST5",
  46. "wnm_sleep_mode": "1",
  47. "bss_transition": "1" }
  48. hostapd.add_ap(apdev[0]['ifname'], params)
  49. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  50. dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
  51. addr = dev[0].p2p_interface_addr()
  52. hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info")
  53. ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"])
  54. if ev is None:
  55. raise Exception("Timeout while waiting for ESS disassociation imminent")
  56. if "0 1024 http://example.com/session-info" not in ev:
  57. raise Exception("Unexpected ESS disassociation imminent message contents")
  58. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  59. if ev is None:
  60. raise Exception("Timeout while waiting for re-connection scan")
  61. def test_wnm_ess_disassoc_imminent_pmf(dev, apdev):
  62. """WNM ESS Disassociation Imminent"""
  63. params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
  64. params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
  65. params["ieee80211w"] = "2";
  66. params["bss_transition"] = "1"
  67. hostapd.add_ap(apdev[0]['ifname'], params)
  68. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  69. dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2",
  70. key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412")
  71. addr = dev[0].p2p_interface_addr()
  72. hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info")
  73. ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"])
  74. if ev is None:
  75. raise Exception("Timeout while waiting for ESS disassociation imminent")
  76. if "1 1024 http://example.com/session-info" not in ev:
  77. raise Exception("Unexpected ESS disassociation imminent message contents")
  78. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  79. if ev is None:
  80. raise Exception("Timeout while waiting for re-connection scan")
  81. def check_wnm_sleep_mode_enter_exit(hapd, dev):
  82. addr = dev.p2p_interface_addr()
  83. sta = hapd.get_sta(addr)
  84. if "[WNM_SLEEP_MODE]" in sta['flags']:
  85. raise Exception("Station unexpectedly in WNM-Sleep Mode")
  86. logger.info("Going to WNM Sleep Mode")
  87. dev.request("WNM_SLEEP enter")
  88. time.sleep(0.5)
  89. sta = hapd.get_sta(addr)
  90. if "[WNM_SLEEP_MODE]" not in sta['flags']:
  91. raise Exception("Station failed to enter WNM-Sleep Mode")
  92. logger.info("Waking up from WNM Sleep Mode")
  93. dev.request("WNM_SLEEP exit")
  94. time.sleep(0.5)
  95. sta = hapd.get_sta(addr)
  96. if "[WNM_SLEEP_MODE]" in sta['flags']:
  97. raise Exception("Station failed to exit WNM-Sleep Mode")
  98. def test_wnm_sleep_mode_open(dev, apdev):
  99. """WNM Sleep Mode - open"""
  100. params = { "ssid": "test-wnm",
  101. "time_advertisement": "2",
  102. "time_zone": "EST5",
  103. "wnm_sleep_mode": "1",
  104. "bss_transition": "1" }
  105. hostapd.add_ap(apdev[0]['ifname'], params)
  106. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  107. dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
  108. check_wnm_sleep_mode_enter_exit(hapd, dev[0])
  109. def test_wnm_sleep_mode_rsn(dev, apdev):
  110. """WNM Sleep Mode - RSN"""
  111. params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
  112. params["time_advertisement"] = "2"
  113. params["time_zone"] = "EST5"
  114. params["wnm_sleep_mode"] = "1"
  115. params["bss_transition"] = "1"
  116. hostapd.add_ap(apdev[0]['ifname'], params)
  117. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  118. dev[0].connect("test-wnm-rsn", psk="12345678", scan_freq="2412")
  119. check_wnm_sleep_mode_enter_exit(hapd, dev[0])
  120. def test_wnm_sleep_mode_rsn_pmf(dev, apdev):
  121. """WNM Sleep Mode - RSN with PMF"""
  122. wt = Wlantest()
  123. wt.flush()
  124. wt.add_passphrase("12345678")
  125. params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
  126. params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
  127. params["ieee80211w"] = "2";
  128. params["time_advertisement"] = "2"
  129. params["time_zone"] = "EST5"
  130. params["wnm_sleep_mode"] = "1"
  131. params["bss_transition"] = "1"
  132. hostapd.add_ap(apdev[0]['ifname'], params)
  133. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  134. dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2",
  135. key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412")
  136. check_wnm_sleep_mode_enter_exit(hapd, dev[0])