]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_ap_hs20.py
tests: Verify that STATUS sp_type is valid for Interworking
[thirdparty/hostap.git] / tests / hwsim / test_ap_hs20.py
CommitLineData
93a06242
JM
1#!/usr/bin/python
2#
3# Hotspot 2.0 tests
4# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
5#
6# This software may be distributed under the terms of the BSD license.
7# See README for more details.
8
9import time
10import subprocess
11import logging
12logger = logging.getLogger(__name__)
efd43d85
JM
13import os.path
14import subprocess
93a06242
JM
15
16import hostapd
17
18def hs20_ap_params():
19 params = hostapd.wpa2_params(ssid="test-hs20")
20 params['wpa_key_mgmt'] = "WPA-EAP"
21 params['ieee80211w'] = "1"
22 params['ieee8021x'] = "1"
23 params['auth_server_addr'] = "127.0.0.1"
24 params['auth_server_port'] = "1812"
25 params['auth_server_shared_secret'] = "radius"
26 params['interworking'] = "1"
27 params['access_network_type'] = "14"
28 params['internet'] = "1"
29 params['asra'] = "0"
30 params['esr'] = "0"
31 params['uesa'] = "0"
32 params['venue_group'] = "7"
33 params['venue_type'] = "1"
34 params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
35 params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
36 "fedcba" ]
37 params['domain_name'] = "example.com,another.example.com"
38 params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
39 "0,another.example.com" ]
40 params['hs20'] = "1"
41 params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
42 params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
43 params['hs20_operating_class'] = "5173"
44 params['anqp_3gpp_cell_net'] = "244,91"
45 return params
46
47def test_ap_hs20_select(dev, apdev):
48 """Hotspot 2.0 network selection"""
49 bssid = apdev[0]['bssid']
50 params = hs20_ap_params()
51 params['hessid'] = bssid
52 hostapd.add_ap(apdev[0]['ifname'], params)
53
54 dev[0].request("SET interworking 1")
55 dev[0].request("SET hs20 1")
56
57 id = dev[0].add_cred()
58 dev[0].set_cred_quoted(id, "realm", "example.com");
59 dev[0].set_cred_quoted(id, "username", "test");
60 dev[0].set_cred_quoted(id, "password", "secret");
61 dev[0].set_cred_quoted(id, "domain", "example.com");
62
63 dev[0].dump_monitor()
64 dev[0].request("INTERWORKING_SELECT")
65 ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
66 timeout=15)
67 if ev is None:
68 raise Exception("Network selection timed out");
69 if "INTERWORKING-NO-MATCH" in ev:
70 raise Exception("Matching network not found")
71 if bssid not in ev:
72 raise Exception("Unexpected BSSID in match")
73 if "type=home" not in ev:
74 raise Exception("Home network not recognized")
75
0076a18f
JM
76 dev[0].remove_cred(id)
77 id = dev[0].add_cred()
78 dev[0].set_cred_quoted(id, "realm", "example.com")
79 dev[0].set_cred_quoted(id, "username", "test")
80 dev[0].set_cred_quoted(id, "password", "secret")
81 dev[0].set_cred_quoted(id, "domain", "no.match.example.com")
93a06242
JM
82 dev[0].dump_monitor()
83 dev[0].request("INTERWORKING_SELECT")
84 ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
85 timeout=15)
86 if ev is None:
87 raise Exception("Network selection timed out");
88 if "INTERWORKING-NO-MATCH" in ev:
89 raise Exception("Matching network not found")
90 if bssid not in ev:
91 raise Exception("Unexpected BSSID in match")
92 if "type=roaming" not in ev:
93 raise Exception("Roaming network not recognized")
94
95 dev[0].set_cred_quoted(id, "realm", "no.match.example.com");
96 dev[0].dump_monitor()
97 dev[0].request("INTERWORKING_SELECT")
98 ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
99 timeout=15)
100 if ev is None:
101 raise Exception("Network selection timed out");
102 if "INTERWORKING-NO-MATCH" not in ev:
103 raise Exception("Unexpected network match")
efd43d85
JM
104
105def test_ap_hs20_ext_sim(dev, apdev):
106 """Hotspot 2.0 with external SIM processing"""
107 if not os.path.exists("/tmp/hlr_auc_gw.sock"):
108 logger.info("No hlr_auc_gw available");
109 return "skip"
110 if not os.path.exists("../../hostapd/hlr_auc_gw"):
111 logger.info("No hlr_auc_gw available");
112 return "skip"
113 bssid = apdev[0]['bssid']
114 params = hs20_ap_params()
115 params['hessid'] = bssid
116 params['anqp_3gpp_cell_net'] = "232,01"
117 params['domain_name'] = "wlan.mnc001.mcc232.3gppnetwork.org"
118 hostapd.add_ap(apdev[0]['ifname'], params)
119
120 dev[0].request("SET interworking 1")
121 dev[0].request("SET hs20 1")
122 dev[0].request("SET external_sim 1")
123
124 id = dev[0].add_cred()
125 dev[0].set_cred_quoted(id, "imsi", "23201-0000000000")
126 dev[0].set_cred(id, "eap", "SIM")
127
128 dev[0].dump_monitor()
129 dev[0].request("INTERWORKING_SELECT")
130 ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
131 timeout=15)
132 if ev is None:
133 raise Exception("Network selection timed out")
134 if "INTERWORKING-NO-MATCH" in ev:
135 raise Exception("Matching network not found")
136 if bssid not in ev:
137 raise Exception("Unexpected BSSID in match")
138 if "type=home" not in ev:
139 raise Exception("Home network not recognized")
140
141 dev[0].request("INTERWORKING_CONNECT " + bssid)
142
143 ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
144 if ev is None:
145 raise Exception("Network connected timed out")
146 if "(SIM)" not in ev:
147 raise Exception("Unexpected EAP method selection")
148
149 ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
150 if ev is None:
151 raise Exception("Wait for external SIM processing request timed out")
152 p = ev.split(':', 2)
153 if p[1] != "GSM-AUTH":
154 raise Exception("Unexpected CTRL-REQ-SIM type")
155 id = p[0].split('-')[3]
156 rand = p[2].split(' ')[0]
157
158 res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
159 "-m",
160 "auth_serv/hlr_auc_gw.milenage_db",
161 "GSM-AUTH-REQ 232010000000000 " + rand])
162 if "GSM-AUTH-RESP" not in res:
163 raise Exception("Unexpected hlr_auc_gw response")
164 resp = res.split(' ')[2].rstrip()
165
166 dev[0].request("CTRL-RSP-SIM-" + id + ":GSM-AUTH:" + resp)
167 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
168 if ev is None:
169 raise Exception("Connection timed out")
f4defd91
JM
170
171 type = dev[0].get_status_field("sp_type")
172 if type is None:
173 raise Exception("sp_type not available")
174 if type != "home":
175 raise Exception("sp_type did not indicate home network")