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