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 7import binascii 8from remotehost import remote_compatible 9import logging 10logger = logging.getLogger() 11import time 12 13import hwsim_utils 14import hostapd 15from wpasupplicant import WpaSupplicant 16from utils import radiotap_build, start_monitor, stop_monitor 17 18def test_monitor_iface_open(dev, apdev): 19 """Open connection using cfg80211 monitor interface on AP""" 20 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') 21 wpas.interface_add("wlan5", drv_params="use_monitor=1") 22 id = wpas.add_network() 23 wpas.set_network(id, "mode", "2") 24 wpas.set_network_quoted(id, "ssid", "monitor-iface") 25 wpas.set_network(id, "key_mgmt", "NONE") 26 wpas.set_network(id, "frequency", "2412") 27 wpas.connect_network(id) 28 29 dev[0].connect("monitor-iface", key_mgmt="NONE", scan_freq="2412") 30 31def test_monitor_iface_wpa2_psk(dev, apdev): 32 """WPA2-PSK connection using cfg80211 monitor interface on AP""" 33 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') 34 wpas.interface_add("wlan5", drv_params="use_monitor=1") 35 id = wpas.add_network() 36 wpas.set_network(id, "mode", "2") 37 wpas.set_network_quoted(id, "ssid", "monitor-iface-wpa2") 38 wpas.set_network(id, "proto", "WPA2") 39 wpas.set_network(id, "key_mgmt", "WPA-PSK") 40 wpas.set_network_quoted(id, "psk", "12345678") 41 wpas.set_network(id, "pairwise", "CCMP") 42 wpas.set_network(id, "group", "CCMP") 43 wpas.set_network(id, "frequency", "2412") 44 wpas.connect_network(id) 45 46 dev[0].connect("monitor-iface-wpa2", psk="12345678", scan_freq="2412") 47 48def test_monitor_iface_multi_bss(dev, apdev): 49 """AP mode mmonitor interface with hostapd multi-BSS setup""" 50 params = {"ssid": "monitor-iface", "driver_params": "use_monitor=1"} 51 hapd = hostapd.add_ap(apdev[0], params) 52 hostapd.add_bss(apdev[0], apdev[0]['ifname'] + '-2', 'bss-2.conf') 53 dev[0].connect("monitor-iface", key_mgmt="NONE", scan_freq="2412") 54 dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412") 55 56@remote_compatible 57def test_monitor_iface_unknown_sta(dev, apdev): 58 """AP mode monitor interface and Data frame from unknown STA""" 59 ssid = "monitor-iface-pmf" 60 passphrase = "12345678" 61 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) 62 params["wpa_key_mgmt"] = "WPA-PSK-SHA256" 63 params["ieee80211w"] = "2" 64 params['driver_params'] = "use_monitor=1" 65 hapd = hostapd.add_ap(apdev[0], params) 66 67 bssid = apdev[0]['bssid'] 68 addr = dev[0].p2p_interface_addr() 69 dev[0].connect(ssid, psk=passphrase, ieee80211w="2", 70 key_mgmt="WPA-PSK-SHA256", proto="WPA2", 71 scan_freq="2412") 72 dev[0].request("DROP_SA") 73 # This protected Deauth will be ignored by the STA 74 hapd.request("DEAUTHENTICATE " + addr) 75 # But the unprotected Deauth from TX frame-from-unassoc-STA will now be 76 # processed 77 try: 78 sock = start_monitor(apdev[1]["ifname"]) 79 radiotap = radiotap_build() 80 81 bssid = hapd.own_addr().replace(':', '') 82 addr = dev[0].own_addr().replace(':', '') 83 84 # Inject Data frame from STA to AP since we not have SA in place 85 # anymore for normal data TX 86 frame = binascii.unhexlify("48010000" + bssid + addr + bssid + "0000") 87 sock.send(radiotap + frame) 88 finally: 89 stop_monitor(apdev[1]["ifname"]) 90 91 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5) 92 if ev is None: 93 raise Exception("No disconnection") 94 dev[0].request("DISCONNECT") 95