test_ssid.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. import logging
  8. logger = logging.getLogger()
  9. import hostapd
  10. def test_ssid_hex_encoded(dev, apdev):
  11. """SSID configuration using hex encoded version"""
  12. hostapd.add_ap(apdev[0]['ifname'], { "ssid2": '68656c6c6f' })
  13. dev[0].connect("hello", key_mgmt="NONE", scan_freq="2412")
  14. dev[1].connect(ssid2="68656c6c6f", key_mgmt="NONE", scan_freq="2412")
  15. def test_ssid_printf_encoded(dev, apdev):
  16. """SSID configuration using printf encoded version"""
  17. hostapd.add_ap(apdev[0]['ifname'], { "ssid2": 'P"\\0hello\\nthere"' })
  18. dev[0].connect(ssid2="0068656c6c6f0a7468657265", key_mgmt="NONE",
  19. scan_freq="2412")
  20. dev[1].connect(ssid2='P"\\x00hello\\nthere"', key_mgmt="NONE",
  21. scan_freq="2412")
  22. ssid = dev[0].get_status_field("ssid")
  23. bss = dev[1].get_bss(apdev[0]['bssid'])
  24. if ssid != bss['ssid']:
  25. raise Exception("Unexpected difference in SSID")
  26. dev[2].connect(ssid2='P"' + ssid + '"', key_mgmt="NONE", scan_freq="2412")
  27. def test_ssid_1_octet(dev, apdev):
  28. """SSID with one octet"""
  29. hostapd.add_ap(apdev[0]['ifname'], { "ssid": '1' })
  30. dev[0].connect("1", key_mgmt="NONE", scan_freq="2412")
  31. def test_ssid_32_octets(dev, apdev):
  32. """SSID with 32 octets"""
  33. hostapd.add_ap(apdev[0]['ifname'],
  34. { "ssid": '1234567890abcdef1234567890ABCDEF' })
  35. dev[0].connect("1234567890abcdef1234567890ABCDEF", key_mgmt="NONE",
  36. scan_freq="2412")
  37. def test_ssid_utf8(dev, apdev):
  38. """SSID with UTF8 encoding"""
  39. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'testi-åäöÅÄÖ-testi',
  40. "utf8_ssid": "1" })
  41. dev[0].connect("testi-åäöÅÄÖ-testi", key_mgmt="NONE", scan_freq="2412")
  42. dev[1].connect(ssid2="74657374692dc3a5c3a4c3b6c385c384c3962d7465737469",
  43. key_mgmt="NONE", scan_freq="2412")
  44. # verify ctrl_iface for coverage
  45. addrs = [ dev[0].p2p_interface_addr(), dev[1].p2p_interface_addr() ]
  46. sta = hapd.get_sta(None)
  47. if sta['addr'] not in addrs:
  48. raise Exception("Unexpected STA address")
  49. sta2 = hapd.get_sta(sta['addr'], next=True)
  50. if sta2['addr'] not in addrs:
  51. raise Exception("Unexpected STA2 address")
  52. sta3 = hapd.get_sta(sta2['addr'], next=True)
  53. if len(sta3) != 0:
  54. raise Exception("Unexpected STA iteration result (did not stop)")
  55. def test_ssid_hidden(dev, apdev):
  56. """Hidden SSID"""
  57. hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret',
  58. "ignore_broadcast_ssid": "1" })
  59. dev[1].connect("secret", key_mgmt="NONE", scan_freq="2412",
  60. wait_connect=False)
  61. dev[0].connect("secret", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
  62. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  63. if ev is not None:
  64. raise Exception("Unexpected connection")
  65. def test_ssid_hidden2(dev, apdev):
  66. """Hidden SSID using zero octets as payload"""
  67. hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret2',
  68. "ignore_broadcast_ssid": "2" })
  69. dev[1].connect("secret2", key_mgmt="NONE", scan_freq="2412",
  70. wait_connect=False)
  71. dev[0].connect("secret2", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
  72. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  73. if ev is not None:
  74. raise Exception("Unexpected connection")
  75. def test_ssid_hidden_wpa2(dev, apdev):
  76. """Hidden SSID with WPA2-PSK"""
  77. params = hostapd.wpa2_params(ssid="secret", passphrase="12345678")
  78. params["ignore_broadcast_ssid"] = "1"
  79. hostapd.add_ap(apdev[0]['ifname'], params)
  80. dev[1].connect("secret", psk="12345678", scan_freq="2412",
  81. wait_connect=False)
  82. dev[0].connect("secret", psk="12345678", scan_freq="2412", scan_ssid="1")
  83. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  84. if ev is not None:
  85. raise Exception("Unexpected connection")