From 93a06242ce368d2a226d9c7f1b33fc8e16b81ba0 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 1 Apr 2013 01:01:24 +0300 Subject: [PATCH] tests: Add a test case for Hotspot 2.0 network selection Signed-hostap: Jouni Malinen --- tests/hwsim/hostapd.py | 13 +++-- tests/hwsim/test_ap_hs20.py | 96 ++++++++++++++++++++++++++++++++++++ tests/hwsim/wpasupplicant.py | 24 +++++++++ 3 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 tests/hwsim/test_ap_hs20.py diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index fff32afad..db586e9b4 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -102,12 +102,19 @@ def add_ap(ifname, params): if not hapd.ping(): raise Exception("Could not ping hostapd") hapd.set_defaults() - fields = [ "ssid", "wpa_passphrase", "wpa", "wpa_key_mgmt", - "wpa_pairwise", "rsn_pairwise", "ieee80211w", "wep_key0", - "eap_server", "wps_state", "ap_pin", "wps_independent" ] + fields = [ "ssid", "wpa_passphrase", "wpa_key_mgmt", "wpa", + "wpa_pairwise", "rsn_pairwise", "auth_server_addr" ] for field in fields: if field in params: hapd.set(field, params[field]) + for f,v in params.items(): + if f in fields: + continue + if isinstance(v, list): + for val in v: + hapd.set(f, val) + else: + hapd.set(f, v) hapd.enable() def wpa2_params(ssid=None, passphrase=None): diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py new file mode 100644 index 000000000..def7bfedd --- /dev/null +++ b/tests/hwsim/test_ap_hs20.py @@ -0,0 +1,96 @@ +#!/usr/bin/python +# +# Hotspot 2.0 tests +# Copyright (c) 2013, Jouni Malinen +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import time +import subprocess +import logging +logger = logging.getLogger(__name__) + +import hostapd + +def hs20_ap_params(): + params = hostapd.wpa2_params(ssid="test-hs20") + params['wpa_key_mgmt'] = "WPA-EAP" + params['ieee80211w'] = "1" + params['ieee8021x'] = "1" + params['auth_server_addr'] = "127.0.0.1" + params['auth_server_port'] = "1812" + params['auth_server_shared_secret'] = "radius" + params['interworking'] = "1" + params['access_network_type'] = "14" + params['internet'] = "1" + params['asra'] = "0" + params['esr'] = "0" + params['uesa'] = "0" + params['venue_group'] = "7" + params['venue_type'] = "1" + params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ] + params['roaming_consortium'] = [ "112233", "1020304050", "010203040506", + "fedcba" ] + params['domain_name'] = "example.com,another.example.com" + params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]", + "0,another.example.com" ] + params['hs20'] = "1" + params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000" + params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ] + params['hs20_operating_class'] = "5173" + params['anqp_3gpp_cell_net'] = "244,91" + return params + +def test_ap_hs20_select(dev, apdev): + """Hotspot 2.0 network selection""" + bssid = apdev[0]['bssid'] + params = hs20_ap_params() + params['hessid'] = bssid + hostapd.add_ap(apdev[0]['ifname'], params) + + dev[0].request("SET interworking 1") + dev[0].request("SET hs20 1") + + id = dev[0].add_cred() + dev[0].set_cred_quoted(id, "realm", "example.com"); + dev[0].set_cred_quoted(id, "username", "test"); + dev[0].set_cred_quoted(id, "password", "secret"); + dev[0].set_cred_quoted(id, "domain", "example.com"); + + dev[0].dump_monitor() + dev[0].request("INTERWORKING_SELECT") + ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"], + timeout=15) + if ev is None: + raise Exception("Network selection timed out"); + if "INTERWORKING-NO-MATCH" in ev: + raise Exception("Matching network not found") + if bssid not in ev: + raise Exception("Unexpected BSSID in match") + if "type=home" not in ev: + raise Exception("Home network not recognized") + + dev[0].set_cred_quoted(id, "domain", "no.match.example.com"); + dev[0].dump_monitor() + dev[0].request("INTERWORKING_SELECT") + ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"], + timeout=15) + if ev is None: + raise Exception("Network selection timed out"); + if "INTERWORKING-NO-MATCH" in ev: + raise Exception("Matching network not found") + if bssid not in ev: + raise Exception("Unexpected BSSID in match") + if "type=roaming" not in ev: + raise Exception("Roaming network not recognized") + + dev[0].set_cred_quoted(id, "realm", "no.match.example.com"); + dev[0].dump_monitor() + dev[0].request("INTERWORKING_SELECT") + ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"], + timeout=15) + if ev is None: + raise Exception("Network selection timed out"); + if "INTERWORKING-NO-MATCH" not in ev: + raise Exception("Unexpected network match") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 1606028f0..4a51da948 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -66,6 +66,30 @@ class WpaSupplicant: raise Exception("SET_NETWORK failed") return None + def add_cred(self): + id = self.request("ADD_CRED") + if "FAIL" in id: + raise Exception("ADD_CRED failed") + return int(id) + + def remove_cred(self, id): + id = self.request("REMOVE_CRED " + str(id)) + if "FAIL" in id: + raise Exception("REMOVE_CRED failed") + return None + + def set_cred(self, id, field, value): + res = self.request("SET_CRED " + str(id) + " " + field + " " + value) + if "FAIL" in res: + raise Exception("SET_CRED failed") + return None + + def set_cred_quoted(self, id, field, value): + res = self.request("SET_CRED " + str(id) + " " + field + ' "' + value + '"') + if "FAIL" in res: + raise Exception("SET_CRED failed") + return None + def select_network(self, id): id = self.request("SELECT_NETWORK " + str(id)) if "FAIL" in id: