2013-12-30 17:17:02 -05:00
|
|
|
# cfg80211 connect command (SME in the driver/firmware)
|
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
|
|
|
import time
|
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
import hostapd
|
|
|
|
from wpasupplicant import WpaSupplicant
|
2015-11-25 08:47:16 -05:00
|
|
|
from p2p_utils import *
|
2020-04-18 04:05:49 -04:00
|
|
|
from utils import *
|
2013-12-30 17:17:02 -05:00
|
|
|
|
|
|
|
def test_connect_cmd_open(dev, apdev):
|
|
|
|
"""Open connection using cfg80211 connect command"""
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect",
|
|
|
|
"manage_p2p": "1",
|
|
|
|
"allow_cross_connection": "1"}
|
2016-03-30 04:55:56 -04:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2014-03-02 13:44:05 -05:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
2014-12-20 12:44:40 -05:00
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bg_scan_period="1")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2014-03-02 13:44:05 -05:00
|
|
|
wpas.request("DISCONNECT")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-03-02 13:44:05 -05:00
|
|
|
|
2014-10-26 09:48:57 -04:00
|
|
|
def test_connect_cmd_wep(dev, apdev):
|
|
|
|
"""WEP Open System using cfg80211 connect command"""
|
2020-02-29 09:52:39 -05:00
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
check_wep_capa(wpas)
|
|
|
|
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect-wep", "wep_key0": '"hello"'}
|
2016-03-30 04:55:56 -04:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-10-26 09:48:57 -04:00
|
|
|
|
|
|
|
wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
wep_key0='"hello"')
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2014-10-26 09:48:57 -04:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
|
|
|
wpas.request("DISCONNECT")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-10-26 09:48:57 -04:00
|
|
|
|
|
|
|
def test_connect_cmd_wep_shared(dev, apdev):
|
|
|
|
"""WEP Shared key using cfg80211 connect command"""
|
2020-02-29 09:52:39 -05:00
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
check_wep_capa(wpas)
|
|
|
|
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect-wep", "wep_key0": '"hello"',
|
|
|
|
"auth_algs": "2"}
|
2016-03-30 04:55:56 -04:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-10-26 09:48:57 -04:00
|
|
|
|
|
|
|
id = wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
auth_alg="SHARED", wep_key0='"hello"')
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2014-10-26 09:48:57 -04:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.remove_network(id)
|
|
|
|
wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
auth_alg="OPEN SHARED", wep_key0='"hello"')
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2014-10-26 09:48:57 -04:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
|
|
|
wpas.request("DISCONNECT")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-10-26 09:48:57 -04:00
|
|
|
|
2014-03-02 13:44:05 -05:00
|
|
|
def test_connect_cmd_p2p_management(dev, apdev):
|
|
|
|
"""Open connection using cfg80211 connect command and AP using P2P management"""
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect",
|
|
|
|
"manage_p2p": "1",
|
|
|
|
"allow_cross_connection": "0"}
|
2016-03-30 04:55:56 -04:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2013-12-30 17:17:02 -05:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2013-12-30 17:17:02 -05:00
|
|
|
wpas.request("DISCONNECT")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2013-12-30 17:17:02 -05:00
|
|
|
|
|
|
|
def test_connect_cmd_wpa2_psk(dev, apdev):
|
|
|
|
"""WPA2-PSK connection using cfg80211 connect command"""
|
|
|
|
params = hostapd.wpa2_params(ssid="sta-connect", passphrase="12345678")
|
2016-03-30 04:55:56 -04:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2013-12-30 17:17:02 -05:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", psk="12345678", scan_freq="2412")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2013-12-30 17:17:02 -05:00
|
|
|
wpas.request("DISCONNECT")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-01-04 01:28:02 -05:00
|
|
|
|
|
|
|
def test_connect_cmd_concurrent_grpform_while_connecting(dev, apdev):
|
|
|
|
"""Concurrent P2P group formation while connecting to an AP using cfg80211 connect command"""
|
|
|
|
logger.info("Start connection to an infrastructure AP")
|
2019-03-15 06:10:37 -04:00
|
|
|
hapd = hostapd.add_ap(apdev[0], {"ssid": "test-open"})
|
2014-01-04 01:28:02 -05:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("test-open", key_mgmt="NONE", wait_connect=False)
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2014-01-04 01:28:02 -05:00
|
|
|
|
|
|
|
logger.info("Form a P2P group while connecting to an AP")
|
|
|
|
wpas.request("SET p2p_no_group_iface 0")
|
|
|
|
|
|
|
|
[i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412,
|
|
|
|
r_dev=wpas, r_freq=2412)
|
|
|
|
check_grpform_results(i_res, r_res)
|
|
|
|
remove_group(dev[0], wpas)
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2014-01-04 01:28:02 -05:00
|
|
|
|
|
|
|
logger.info("Confirm AP connection after P2P group removal")
|
2014-10-19 10:54:49 -04:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
2014-06-01 16:03:14 -04:00
|
|
|
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
2014-06-01 16:03:14 -04:00
|
|
|
def test_connect_cmd_reject_assoc(dev, apdev):
|
|
|
|
"""Connection using cfg80211 connect command getting rejected"""
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect",
|
|
|
|
"require_ht": "1"}
|
2016-03-30 04:55:56 -04:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2014-06-01 16:03:14 -04:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
disable_ht="1", wait_connect=False)
|
2019-03-15 16:42:18 -04:00
|
|
|
ev = wpas.wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=15)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Association rejection timed out")
|
|
|
|
if "status_code=27" not in ev:
|
|
|
|
raise Exception("Unexpected rejection status code")
|
2014-06-01 16:20:36 -04:00
|
|
|
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
2014-06-01 16:20:36 -04:00
|
|
|
def test_connect_cmd_disconnect_event(dev, apdev):
|
|
|
|
"""Connection using cfg80211 connect command getting disconnected by the AP"""
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect"}
|
2016-03-30 04:55:56 -04:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-06-01 16:20:36 -04:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
|
|
|
|
if "OK" not in hapd.request("DEAUTHENTICATE " + wpas.p2p_interface_addr()):
|
|
|
|
raise Exception("DEAUTHENTICATE command failed")
|
|
|
|
ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Disconnection event timed out")
|
|
|
|
# This event was actually based on deauthenticate event since we force
|
|
|
|
# connect command to be used with a driver that supports auth+assoc for
|
|
|
|
# testing purposes. Anyway, wait some time to allow the debug log to capture
|
|
|
|
# the following NL80211_CMD_DISCONNECT event.
|
|
|
|
time.sleep(0.1)
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2015-08-28 12:01:47 -04:00
|
|
|
|
2015-12-30 06:29:32 -05:00
|
|
|
# Clean up to avoid causing issue for following test cases
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=2)
|
|
|
|
wpas.flush_scan_cache()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
wpas.interface_remove("wlan5")
|
|
|
|
del wpas
|
|
|
|
|
2015-08-28 12:01:47 -04:00
|
|
|
def test_connect_cmd_roam(dev, apdev):
|
|
|
|
"""cfg80211 connect command to trigger roam"""
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect"}
|
2016-03-30 04:55:56 -04:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2015-08-28 12:01:47 -04:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412")
|
2015-10-03 18:42:42 -04:00
|
|
|
wpas.dump_monitor()
|
2015-08-28 12:01:47 -04:00
|
|
|
|
2016-03-30 04:55:56 -04:00
|
|
|
hostapd.add_ap(apdev[1], params)
|
2015-10-03 17:35:12 -04:00
|
|
|
wpas.scan_for_bss(apdev[1]['bssid'], freq=2412, force_scan=True)
|
2015-08-28 12:01:47 -04:00
|
|
|
wpas.roam(apdev[1]['bssid'])
|
2015-10-03 18:42:42 -04:00
|
|
|
time.sleep(0.1)
|
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2017-05-11 17:33:06 -04:00
|
|
|
|
|
|
|
def test_connect_cmd_bssid_hint(dev, apdev):
|
|
|
|
"""cfg80211 connect command with bssid_hint"""
|
2019-03-15 06:10:37 -04:00
|
|
|
params = {"ssid": "sta-connect"}
|
2017-05-11 17:33:06 -04:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
|
|
|
hostapd.add_ap(apdev[1], params)
|
|
|
|
|
|
|
|
# This does not really give full coverage with mac80211_hwsim since the
|
|
|
|
# driver does not end up claiming support for driver-based BSS selection.
|
|
|
|
# Anyway, some test coverage can be achieved for setting the parameter and
|
|
|
|
# checking that it does not prevent connection with another BSSID.
|
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bssid_hint=apdev[0]['bssid'])
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
|
|
|
wpas.request("BSS_FLUSH 0")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bssid_hint='22:33:44:55:66:77')
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
|
|
|
# Additional coverage using ap_scan=2 to prevent scan entry -based selection
|
|
|
|
# within wpa_supplicant from overriding bssid_hint.
|
|
|
|
|
|
|
|
try:
|
|
|
|
if "OK" not in wpas.request("AP_SCAN 2"):
|
|
|
|
raise Exception("Failed to set AP_SCAN 2")
|
|
|
|
wpas.request("BSS_FLUSH 0")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bssid_hint='22:33:44:55:66:77')
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
finally:
|
|
|
|
wpas.request("AP_SCAN 1")
|
2019-02-25 14:58:28 -05:00
|
|
|
wpas.flush_scan_cache()
|