]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_cfg80211.py
tests: Make HS 2.0 test cases more robust
[thirdparty/hostap.git] / tests / hwsim / test_cfg80211.py
1 # cfg80211 test cases
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import binascii
8
9 import hostapd
10 from nl80211 import *
11
12 def nl80211_command(dev, cmd, attr):
13 res = dev.request("VENDOR ffffffff {} {}".format(nl80211_cmd[cmd],
14 binascii.hexlify(attr)))
15 if "FAIL" in res:
16 raise Exception("nl80211 command failed")
17 return binascii.unhexlify(res)
18
19 def test_cfg80211_disassociate(dev, apdev):
20 """cfg80211 disassociation command"""
21 hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
22 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
23 ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
24 if ev is None:
25 raise Exception("No connection event received from hostapd")
26
27 ifindex = int(dev[0].get_driver_status_field("ifindex"))
28 attrs = build_nl80211_attr_u32('IFINDEX', ifindex)
29 attrs += build_nl80211_attr_u16('REASON_CODE', 1)
30 attrs += build_nl80211_attr_mac('MAC', apdev[0]['bssid'])
31 nl80211_command(dev[0], 'DISASSOCIATE', attrs)
32
33 ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
34 if ev is None:
35 raise Exception("No disconnection event received from hostapd")