test_cfg80211.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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. import binascii
  7. import hostapd
  8. from nl80211 import *
  9. def nl80211_command(dev, cmd, attr):
  10. res = dev.request("VENDOR ffffffff {} {}".format(nl80211_cmd[cmd],
  11. binascii.hexlify(attr)))
  12. if "FAIL" in res:
  13. raise Exception("nl80211 command failed")
  14. return binascii.unhexlify(res)
  15. def test_cfg80211_disassociate(dev, apdev):
  16. """cfg80211 disassociation command"""
  17. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  18. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  19. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  20. if ev is None:
  21. raise Exception("No connection event received from hostapd")
  22. ifindex = int(dev[0].get_driver_status_field("ifindex"))
  23. attrs = build_nl80211_attr_u32('IFINDEX', ifindex)
  24. attrs += build_nl80211_attr_u16('REASON_CODE', 1)
  25. attrs += build_nl80211_attr_mac('MAC', apdev[0]['bssid'])
  26. nl80211_command(dev[0], 'DISASSOCIATE', attrs)
  27. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
  28. if ev is None:
  29. raise Exception("No disconnection event received from hostapd")