]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_ssid.py
tests: sigma_dut controlled STA and beacon protection
[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
9fd6804d 8from remotehost import remote_compatible
f19ee5b7
JM
9import logging
10logger = logging.getLogger()
11
12import hostapd
13
9fd6804d 14@remote_compatible
f19ee5b7
JM
15def test_ssid_hex_encoded(dev, apdev):
16 """SSID configuration using hex encoded version"""
fab49f61 17 hostapd.add_ap(apdev[0], {"ssid2": '68656c6c6f'})
f19ee5b7
JM
18 dev[0].connect("hello", key_mgmt="NONE", scan_freq="2412")
19 dev[1].connect(ssid2="68656c6c6f", key_mgmt="NONE", scan_freq="2412")
20
21def test_ssid_printf_encoded(dev, apdev):
22 """SSID configuration using printf encoded version"""
fab49f61 23 hostapd.add_ap(apdev[0], {"ssid2": 'P"\\0hello\\nthere"'})
f19ee5b7
JM
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
9fd6804d 34@remote_compatible
f19ee5b7
JM
35def test_ssid_1_octet(dev, apdev):
36 """SSID with one octet"""
fab49f61 37 hostapd.add_ap(apdev[0], {"ssid": '1'})
f19ee5b7
JM
38 dev[0].connect("1", key_mgmt="NONE", scan_freq="2412")
39
9fd6804d 40@remote_compatible
f19ee5b7
JM
41def test_ssid_32_octets(dev, apdev):
42 """SSID with 32 octets"""
8b8a1864 43 hostapd.add_ap(apdev[0],
fab49f61 44 {"ssid": '1234567890abcdef1234567890ABCDEF'})
f19ee5b7
JM
45 dev[0].connect("1234567890abcdef1234567890ABCDEF", key_mgmt="NONE",
46 scan_freq="2412")
47
44fa13b1
JM
48def test_ssid_32_octets_nul_term(dev, apdev):
49 """SSID with 32 octets with nul at the end"""
50 ssid = 'P"1234567890abcdef1234567890ABCDE\\x00"'
51 hostapd.add_ap(apdev[0],
fab49f61 52 {"ssid2": ssid})
44fa13b1
JM
53 dev[0].connect(ssid2=ssid, key_mgmt="NONE", scan_freq="2412")
54
9fd6804d 55@remote_compatible
f19ee5b7
JM
56def test_ssid_utf8(dev, apdev):
57 """SSID with UTF8 encoding"""
fab49f61
JM
58 hapd = hostapd.add_ap(apdev[0], {"ssid": 'testi-åäöÅÄÖ-testi',
59 "utf8_ssid": "1"})
f19ee5b7
JM
60 dev[0].connect("testi-åäöÅÄÖ-testi", key_mgmt="NONE", scan_freq="2412")
61 dev[1].connect(ssid2="74657374692dc3a5c3a4c3b6c385c384c3962d7465737469",
62 key_mgmt="NONE", scan_freq="2412")
cce26eb4 63 # verify ctrl_iface for coverage
fab49f61 64 addrs = [dev[0].p2p_interface_addr(), dev[1].p2p_interface_addr()]
cce26eb4
JM
65 sta = hapd.get_sta(None)
66 if sta['addr'] not in addrs:
67 raise Exception("Unexpected STA address")
68 sta2 = hapd.get_sta(sta['addr'], next=True)
69 if sta2['addr'] not in addrs:
70 raise Exception("Unexpected STA2 address")
71 sta3 = hapd.get_sta(sta2['addr'], next=True)
72 if len(sta3) != 0:
73 raise Exception("Unexpected STA iteration result (did not stop)")
f19ee5b7 74
2e2f0f45
JM
75 if "[UTF-8]" not in dev[0].get_bss(hapd.own_addr())['flags']:
76 raise Exception("[UTF-8] flag not included in BSS")
77 if "[UTF-8]" not in dev[0].request("SCAN_RESULTS"):
78 raise Exception("[UTF-8] flag not included in SCAN_RESULTS")
79
7c7234a5
JM
80def clear_scan_cache(hapd, dev):
81 # clear BSS table to avoid issues in following test cases
82 dev[0].request("REMOVE_NETWORK all")
83 dev[1].request("REMOVE_NETWORK all")
84 dev[0].wait_disconnected()
85 hapd.disable()
86 dev[0].flush_scan_cache()
87 dev[1].flush_scan_cache()
88
9fd6804d 89@remote_compatible
f19ee5b7
JM
90def test_ssid_hidden(dev, apdev):
91 """Hidden SSID"""
fab49f61
JM
92 hapd = hostapd.add_ap(apdev[0], {"ssid": 'secret',
93 "ignore_broadcast_ssid": "1"})
f19ee5b7
JM
94 dev[1].connect("secret", key_mgmt="NONE", scan_freq="2412",
95 wait_connect=False)
96 dev[0].connect("secret", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
97 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
98 if ev is not None:
99 raise Exception("Unexpected connection")
7c7234a5 100 clear_scan_cache(hapd, dev)
f19ee5b7 101
9fd6804d 102@remote_compatible
47a7e440
JM
103def test_ssid_hidden2(dev, apdev):
104 """Hidden SSID using zero octets as payload"""
fab49f61
JM
105 hapd = hostapd.add_ap(apdev[0], {"ssid": 'secret2',
106 "ignore_broadcast_ssid": "2"})
47a7e440
JM
107 dev[1].connect("secret2", key_mgmt="NONE", scan_freq="2412",
108 wait_connect=False)
109 dev[0].connect("secret2", key_mgmt="NONE", scan_freq="2412", scan_ssid="1")
110 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
111 if ev is not None:
112 raise Exception("Unexpected connection")
7c7234a5 113 clear_scan_cache(hapd, dev)
47a7e440 114
9fd6804d 115@remote_compatible
f19ee5b7
JM
116def test_ssid_hidden_wpa2(dev, apdev):
117 """Hidden SSID with WPA2-PSK"""
118 params = hostapd.wpa2_params(ssid="secret", passphrase="12345678")
119 params["ignore_broadcast_ssid"] = "1"
8b8a1864 120 hapd = hostapd.add_ap(apdev[0], params)
f19ee5b7
JM
121 dev[1].connect("secret", psk="12345678", scan_freq="2412",
122 wait_connect=False)
123 dev[0].connect("secret", psk="12345678", scan_freq="2412", scan_ssid="1")
124 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
125 if ev is not None:
126 raise Exception("Unexpected connection")
7c7234a5 127 clear_scan_cache(hapd, dev)