test_ap_hs20.py 6.1 KB

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