test_ssid.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- coding: utf-8 -*-
  2. # SSID contents and encoding tests
  3. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  4. #
  5. # This software may be distributed under the terms of the BSD license.
  6. # See README for more details.
  7. from remotehost import remote_compatible
  8. import logging
  9. logger = logging.getLogger()
  10. import hostapd
  11. @remote_compatible
  12. def test_ssid_hex_encoded(dev, apdev):
  13. """SSID configuration using hex encoded version"""
  14. hostapd.add_ap(apdev[0], { "ssid2": '68656c6c6f' })
  15. dev[0].connect("hello", key_mgmt="NONE", scan_freq="2412")
  16. dev[1].connect(ssid2="68656c6c6f", key_mgmt="NONE", scan_freq="2412")
  17. def test_ssid_printf_encoded(dev, apdev):
  18. """SSID configuration using printf encoded version"""
  19. hostapd.add_ap(apdev[0], { "ssid2": 'P"\\0hello\\nthere"' })
  20. dev[0].connect(ssid2="0068656c6c6f0a7468657265", key_mgmt="NONE",
  21. scan_freq="2412")
  22. dev[1].connect(ssid2='P"\\x00hello\\nthere"', key_mgmt="NONE",
  23. scan_freq="2412")
  24. ssid = dev[0].get_status_field("ssid")
  25. bss = dev[1].get_bss(apdev[0]['bssid'])
  26. if ssid != bss['ssid']:
  27. raise Exception("Unexpected difference in SSID")
  28. dev[2].connect(ssid2='P"' + ssid + '"', key_mgmt="NONE", scan_freq="2412")
  29. @remote_compatible
  30. def test_ssid_1_octet(dev, apdev):
  31. """SSID with one octet"""
  32. hostapd.add_ap(apdev[0], { "ssid": '1' })
  33. dev[0].connect("1", key_mgmt="NONE", scan_freq="2412")
  34. @remote_compatible
  35. def test_ssid_32_octets(dev, apdev):
  36. """SSID with 32 octets"""
  37. hostapd.add_ap(apdev[0],
  38. { "ssid": '1234567890abcdef1234567890ABCDEF' })
  39. dev[0].connect("1234567890abcdef1234567890ABCDEF", key_mgmt="NONE",
  40. scan_freq="2412")
  41. @remote_compatible
  42. def test_ssid_utf8(dev, apdev):
  43. """SSID with UTF8 encoding"""
  44. hapd = hostapd.add_ap(apdev[0], { "ssid": 'testi-åäöÅÄÖ-testi',
  45. "utf8_ssid": "1" })
  46. dev[0].connect("testi-åäöÅÄÖ-testi", key_mgmt="NONE", scan_freq="2412")
  47. dev[1].connect(ssid2="74657374692dc3a5c3a4c3b6c385c384c3962d7465737469",
  48. key_mgmt="NONE", scan_freq="2412")
  49. # verify ctrl_iface for coverage
  50. addrs = [ dev[0].p2p_interface_addr(), dev[1].p2p_interface_addr() ]
  51. sta = hapd.get_sta(None)
  52. if sta['addr'] not in addrs:
  53. raise Exception("Unexpected STA address")
  54. sta2 = hapd.get_sta(sta['addr'], next=True)
  55. if sta2['addr'] not in addrs:
  56. raise Exception("Unexpected STA2 address")
  57. sta3 = hapd.get_sta(sta2['addr'], next=True)
  58. if len(sta3) != 0:
  59. raise Exception("Unexpected STA iteration result (did not stop)")
  60. def clear_scan_cache(hapd, dev):
  61. # clear BSS table to avoid issues in following test cases
  62. dev[0].request("REMOVE_NETWORK all")
  63. dev[1].request("REMOVE_NETWORK all")
  64. dev[0].wait_disconnected()
  65. hapd.disable()
  66. dev[0].flush_scan_cache()
  67. dev[1].flush_scan_cache()
  68. @remote_compatible
  69. def test_ssid_hidden(dev, apdev):
  70. """Hidden SSID"""
  71. hapd = hostapd.add_ap(apdev[0], { "ssid": 'secret',
  72. "ignore_broadcast_ssid": "1" })
  73. dev[1].connect("secret", key_mgmt="NONE", scan_freq="2412",
  74. wait_connect=False)
  75. dev[0].connect("secret", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
  76. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  77. if ev is not None:
  78. raise Exception("Unexpected connection")
  79. clear_scan_cache(hapd, dev)
  80. @remote_compatible
  81. def test_ssid_hidden2(dev, apdev):
  82. """Hidden SSID using zero octets as payload"""
  83. hapd = hostapd.add_ap(apdev[0], { "ssid": 'secret2',
  84. "ignore_broadcast_ssid": "2" })
  85. dev[1].connect("secret2", key_mgmt="NONE", scan_freq="2412",
  86. wait_connect=False)
  87. dev[0].connect("secret2", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
  88. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  89. if ev is not None:
  90. raise Exception("Unexpected connection")
  91. clear_scan_cache(hapd, dev)
  92. @remote_compatible
  93. def test_ssid_hidden_wpa2(dev, apdev):
  94. """Hidden SSID with WPA2-PSK"""
  95. params = hostapd.wpa2_params(ssid="secret", passphrase="12345678")
  96. params["ignore_broadcast_ssid"] = "1"
  97. hapd = hostapd.add_ap(apdev[0], params)
  98. dev[1].connect("secret", psk="12345678", scan_freq="2412",
  99. wait_connect=False)
  100. dev[0].connect("secret", psk="12345678", scan_freq="2412", scan_ssid="1")
  101. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  102. if ev is not None:
  103. raise Exception("Unexpected connection")
  104. clear_scan_cache(hapd, dev)