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