test_monitor_interface.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # AP mode using the older monitor interface design
  2. # Copyright (c) 2013, 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. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import time
  10. import hwsim_utils
  11. import hostapd
  12. from wpasupplicant import WpaSupplicant
  13. def test_monitor_iface_open(dev, apdev):
  14. """Open connection using cfg80211 monitor interface on AP"""
  15. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  16. wpas.interface_add("wlan5", drv_params="use_monitor=1")
  17. id = wpas.add_network()
  18. wpas.set_network(id, "mode", "2")
  19. wpas.set_network_quoted(id, "ssid", "monitor-iface")
  20. wpas.set_network(id, "key_mgmt", "NONE")
  21. wpas.set_network(id, "frequency", "2412")
  22. wpas.connect_network(id)
  23. dev[0].connect("monitor-iface", key_mgmt="NONE", scan_freq="2412")
  24. def test_monitor_iface_wpa2_psk(dev, apdev):
  25. """WPA2-PSK connection using cfg80211 monitor interface on AP"""
  26. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  27. wpas.interface_add("wlan5", drv_params="use_monitor=1")
  28. id = wpas.add_network()
  29. wpas.set_network(id, "mode", "2")
  30. wpas.set_network_quoted(id, "ssid", "monitor-iface-wpa2")
  31. wpas.set_network(id, "proto", "WPA2")
  32. wpas.set_network(id, "key_mgmt", "WPA-PSK")
  33. wpas.set_network_quoted(id, "psk", "12345678")
  34. wpas.set_network(id, "pairwise", "CCMP")
  35. wpas.set_network(id, "group", "CCMP")
  36. wpas.set_network(id, "frequency", "2412")
  37. wpas.connect_network(id)
  38. dev[0].connect("monitor-iface-wpa2", psk="12345678", scan_freq="2412")
  39. def test_monitor_iface_multi_bss(dev, apdev):
  40. """AP mode mmonitor interface with hostapd multi-BSS setup"""
  41. params = { "ssid": "monitor-iface", "driver_params": "use_monitor=1" }
  42. hapd = hostapd.add_ap(apdev[0], params)
  43. hostapd.add_bss(apdev[0], apdev[0]['ifname'] + '-2', 'bss-2.conf')
  44. dev[0].connect("monitor-iface", key_mgmt="NONE", scan_freq="2412")
  45. dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412")
  46. @remote_compatible
  47. def test_monitor_iface_unknown_sta(dev, apdev):
  48. """AP mode monitor interface and Data frame from unknown STA"""
  49. ssid = "monitor-iface-pmf"
  50. passphrase = "12345678"
  51. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  52. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  53. params["ieee80211w"] = "2"
  54. params['driver_params'] = "use_monitor=1"
  55. hapd = hostapd.add_ap(apdev[0], params)
  56. bssid = apdev[0]['bssid']
  57. addr = dev[0].p2p_interface_addr()
  58. dev[0].connect(ssid, psk=passphrase, ieee80211w="2",
  59. key_mgmt="WPA-PSK-SHA256", proto="WPA2",
  60. scan_freq="2412")
  61. dev[0].request("DROP_SA")
  62. # This protected Deauth will be ignored by the STA
  63. hapd.request("DEAUTHENTICATE " + addr)
  64. # But the unprotected Deauth from TX frame-from-unassoc-STA will now be
  65. # processed
  66. dev[0].request("DATA_TEST_CONFIG 1")
  67. dev[0].request("DATA_TEST_TX " + bssid + " " + addr + " 0")
  68. dev[0].request("DATA_TEST_CONFIG 0")
  69. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  70. if ev is None:
  71. raise Exception("No disconnection")
  72. dev[0].request("DISCONNECT")