test_ssid.py 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # SSID contents and encoding tests
  5. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  6. #
  7. # This software may be distributed under the terms of the BSD license.
  8. # See README for more details.
  9. import logging
  10. logger = logging.getLogger()
  11. import hostapd
  12. def test_ssid_hex_encoded(dev, apdev):
  13. """SSID configuration using hex encoded version"""
  14. hostapd.add_ap(apdev[0]['ifname'], { "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]['ifname'], { "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. def test_ssid_1_octet(dev, apdev):
  30. """SSID with one octet"""
  31. hostapd.add_ap(apdev[0]['ifname'], { "ssid": '1' })
  32. dev[0].connect("1", key_mgmt="NONE", scan_freq="2412")
  33. def test_ssid_32_octets(dev, apdev):
  34. """SSID with 32 octets"""
  35. hostapd.add_ap(apdev[0]['ifname'],
  36. { "ssid": '1234567890abcdef1234567890ABCDEF' })
  37. dev[0].connect("1234567890abcdef1234567890ABCDEF", key_mgmt="NONE",
  38. scan_freq="2412")
  39. def test_ssid_utf8(dev, apdev):
  40. """SSID with UTF8 encoding"""
  41. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'testi-åäöÅÄÖ-testi',
  42. "utf8_ssid": "1" })
  43. dev[0].connect("testi-åäöÅÄÖ-testi", key_mgmt="NONE", scan_freq="2412")
  44. dev[1].connect(ssid2="74657374692dc3a5c3a4c3b6c385c384c3962d7465737469",
  45. key_mgmt="NONE", scan_freq="2412")
  46. # verify ctrl_iface for coverage
  47. addrs = [ dev[0].p2p_interface_addr(), dev[1].p2p_interface_addr() ]
  48. sta = hapd.get_sta(None)
  49. if sta['addr'] not in addrs:
  50. raise Exception("Unexpected STA address")
  51. sta2 = hapd.get_sta(sta['addr'], next=True)
  52. if sta2['addr'] not in addrs:
  53. raise Exception("Unexpected STA2 address")
  54. sta3 = hapd.get_sta(sta2['addr'], next=True)
  55. if len(sta3) != 0:
  56. raise Exception("Unexpected STA iteration result (did not stop)")
  57. def test_ssid_hidden(dev, apdev):
  58. """Hidden SSID"""
  59. hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret',
  60. "ignore_broadcast_ssid": "1" })
  61. dev[1].connect("secret", key_mgmt="NONE", scan_freq="2412",
  62. wait_connect=False)
  63. dev[0].connect("secret", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
  64. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  65. if ev is not None:
  66. raise Exception("Unexpected connection")
  67. def test_ssid_hidden2(dev, apdev):
  68. """Hidden SSID using zero octets as payload"""
  69. hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret2',
  70. "ignore_broadcast_ssid": "2" })
  71. dev[1].connect("secret2", key_mgmt="NONE", scan_freq="2412",
  72. wait_connect=False)
  73. dev[0].connect("secret2", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
  74. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  75. if ev is not None:
  76. raise Exception("Unexpected connection")
  77. def test_ssid_hidden_wpa2(dev, apdev):
  78. """Hidden SSID with WPA2-PSK"""
  79. params = hostapd.wpa2_params(ssid="secret", passphrase="12345678")
  80. params["ignore_broadcast_ssid"] = "1"
  81. hostapd.add_ap(apdev[0]['ifname'], params)
  82. dev[1].connect("secret", psk="12345678", scan_freq="2412",
  83. wait_connect=False)
  84. dev[0].connect("secret", psk="12345678", scan_freq="2412", scan_ssid="1")
  85. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  86. if ev is not None:
  87. raise Exception("Unexpected connection")