test_wep.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # WEP tests
  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. import logging
  7. logger = logging.getLogger()
  8. import subprocess
  9. from remotehost import remote_compatible
  10. import hostapd
  11. import hwsim_utils
  12. @remote_compatible
  13. def test_wep_open_auth(dev, apdev):
  14. """WEP Open System authentication"""
  15. hapd = hostapd.add_ap(apdev[0],
  16. { "ssid": "wep-open",
  17. "wep_key0": '"hello"' })
  18. dev[0].flush_scan_cache()
  19. dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
  20. scan_freq="2412")
  21. hwsim_utils.test_connectivity(dev[0], hapd)
  22. if "[WEP]" not in dev[0].request("SCAN_RESULTS"):
  23. raise Exception("WEP flag not indicated in scan results")
  24. bss = dev[0].get_bss(apdev[0]['bssid'])
  25. if 'flags' not in bss:
  26. raise Exception("Could not get BSS flags from BSS table")
  27. if "[WEP]" not in bss['flags']:
  28. raise Exception("Unexpected BSS flags: " + bss['flags'])
  29. @remote_compatible
  30. def test_wep_shared_key_auth(dev, apdev):
  31. """WEP Shared Key authentication"""
  32. hapd = hostapd.add_ap(apdev[0],
  33. { "ssid": "wep-shared-key",
  34. "wep_key0": '"hello12345678"',
  35. "auth_algs": "2" })
  36. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  37. wep_key0='"hello12345678"',
  38. scan_freq="2412")
  39. hwsim_utils.test_connectivity(dev[0], hapd)
  40. dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
  41. wep_key0='"hello12345678"',
  42. scan_freq="2412")
  43. @remote_compatible
  44. def test_wep_shared_key_auth_not_allowed(dev, apdev):
  45. """WEP Shared Key authentication not allowed"""
  46. hostapd.add_ap(apdev[0],
  47. { "ssid": "wep-shared-key",
  48. "wep_key0": '"hello12345678"',
  49. "auth_algs": "1" })
  50. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  51. wep_key0='"hello12345678"',
  52. scan_freq="2412", wait_connect=False)
  53. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  54. if ev is not None:
  55. raise Exception("Unexpected association")
  56. def test_wep_shared_key_auth_multi_key(dev, apdev):
  57. """WEP Shared Key authentication with multiple keys"""
  58. hapd = hostapd.add_ap(apdev[0],
  59. { "ssid": "wep-shared-key",
  60. "wep_key0": '"hello12345678"',
  61. "wep_key1": '"other12345678"',
  62. "auth_algs": "2" })
  63. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  64. wep_key0='"hello12345678"',
  65. scan_freq="2412")
  66. dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  67. wep_key0='"hello12345678"',
  68. wep_key1='"other12345678"',
  69. wep_tx_keyidx="1",
  70. scan_freq="2412")
  71. id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  72. wep_key0='"hello12345678"',
  73. wep_key1='"other12345678"',
  74. wep_tx_keyidx="0",
  75. scan_freq="2412")
  76. hwsim_utils.test_connectivity(dev[0], hapd)
  77. hwsim_utils.test_connectivity(dev[1], hapd)
  78. hwsim_utils.test_connectivity(dev[2], hapd)
  79. dev[2].set_network(id, "wep_tx_keyidx", "1")
  80. dev[2].request("REASSOCIATE")
  81. dev[2].wait_connected(timeout=10, error="Reassociation timed out")
  82. hwsim_utils.test_connectivity(dev[2], hapd)
  83. def test_wep_ht_vht(dev, apdev):
  84. """WEP and HT/VHT"""
  85. dev[0].flush_scan_cache()
  86. try:
  87. hapd = None
  88. params = { "ssid": "test-vht40-wep",
  89. "country_code": "SE",
  90. "hw_mode": "a",
  91. "channel": "36",
  92. "ieee80211n": "1",
  93. "ieee80211ac": "1",
  94. "ht_capab": "[HT40+]",
  95. "vht_capab": "",
  96. "vht_oper_chwidth": "0",
  97. "vht_oper_centr_freq_seg0_idx": "0",
  98. "wep_key0": '"hello"' }
  99. hapd = hostapd.add_ap(apdev[0], params)
  100. dev[0].connect("test-vht40-wep", scan_freq="5180", key_mgmt="NONE",
  101. wep_key0='"hello"')
  102. hwsim_utils.test_connectivity(dev[0], hapd)
  103. status = hapd.get_status()
  104. logger.info("hostapd STATUS: " + str(status))
  105. if status["ieee80211n"] != "0":
  106. raise Exception("Unexpected STATUS ieee80211n value")
  107. if status["ieee80211ac"] != "0":
  108. raise Exception("Unexpected STATUS ieee80211ac value")
  109. if status["secondary_channel"] != "0":
  110. raise Exception("Unexpected STATUS secondary_channel value")
  111. finally:
  112. dev[0].request("DISCONNECT")
  113. if hapd:
  114. hapd.request("DISABLE")
  115. subprocess.call(['iw', 'reg', 'set', '00'])
  116. dev[0].flush_scan_cache()