hostapd/tests/hwsim/test_cfg80211.py
Jouni Malinen 9308d0a039 tests: Add initial cfg80211 test
This adds some helper definitions and functions to allow cfg80211 to be
tested with raw nl80211 messages built in the test scripts. The first
test case shows a case where station disassociates instead of
deauthenticates (which is the wpa_supplicant behavior).

Signed-off-by: Jouni Malinen <j@w1.fi>
2014-03-29 11:02:32 +02:00

35 lines
1.3 KiB
Python

# cfg80211 test cases
# Copyright (c) 2014, Jouni Malinen <j@w1.fi>
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
import binascii
import hostapd
from nl80211 import *
def nl80211_command(dev, cmd, attr):
res = dev.request("VENDOR ffffffff {} {}".format(nl80211_cmd[cmd],
binascii.hexlify(attr)))
if "FAIL" in res:
raise Exception("nl80211 command failed")
return binascii.unhexlify(res)
def test_cfg80211_disassociate(dev, apdev):
"""cfg80211 disassociation command"""
hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
if ev is None:
raise Exception("No connection event received from hostapd")
ifindex = int(dev[0].get_driver_status_field("ifindex"))
attrs = build_nl80211_attr_u32('IFINDEX', ifindex)
attrs += build_nl80211_attr_u16('REASON_CODE', 1)
attrs += build_nl80211_attr_mac('MAC', apdev[0]['bssid'])
nl80211_command(dev[0], 'DISASSOCIATE', attrs)
ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
if ev is None:
raise Exception("No disconnection event received from hostapd")