test_ap_hs20.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 interworking_select(dev, bssid, type=None, no_match=False):
  44. dev.dump_monitor()
  45. dev.request("INTERWORKING_SELECT")
  46. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  47. timeout=15)
  48. if ev is None:
  49. raise Exception("Network selection timed out");
  50. if no_match:
  51. if "INTERWORKING-NO-MATCH" not in ev:
  52. raise Exception("Unexpected network match")
  53. return
  54. if "INTERWORKING-NO-MATCH" in ev:
  55. raise Exception("Matching network not found")
  56. if bssid not in ev:
  57. raise Exception("Unexpected BSSID in match")
  58. if type and "type=" + type not in ev:
  59. raise Exception("Network type not recognized correctly")
  60. def check_sp_type(dev, sp_type):
  61. type = dev.get_status_field("sp_type")
  62. if type is None:
  63. raise Exception("sp_type not available")
  64. if type != sp_type:
  65. raise Exception("sp_type did not indicate home network")
  66. def hlr_auc_gw_available():
  67. if not os.path.exists("/tmp/hlr_auc_gw.sock"):
  68. logger.info("No hlr_auc_gw available");
  69. return False
  70. if not os.path.exists("../../hostapd/hlr_auc_gw"):
  71. logger.info("No hlr_auc_gw available");
  72. return False
  73. return True
  74. def interworking_ext_sim_connect(dev, bssid, method):
  75. dev.request("INTERWORKING_CONNECT " + bssid)
  76. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  77. if ev is None:
  78. raise Exception("Network connected timed out")
  79. if "(" + method + ")" not in ev:
  80. raise Exception("Unexpected EAP method selection")
  81. ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15)
  82. if ev is None:
  83. raise Exception("Wait for external SIM processing request timed out")
  84. p = ev.split(':', 2)
  85. if p[1] != "GSM-AUTH":
  86. raise Exception("Unexpected CTRL-REQ-SIM type")
  87. id = p[0].split('-')[3]
  88. rand = p[2].split(' ')[0]
  89. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  90. "-m",
  91. "auth_serv/hlr_auc_gw.milenage_db",
  92. "GSM-AUTH-REQ 232010000000000 " + rand])
  93. if "GSM-AUTH-RESP" not in res:
  94. raise Exception("Unexpected hlr_auc_gw response")
  95. resp = res.split(' ')[2].rstrip()
  96. dev.request("CTRL-RSP-SIM-" + id + ":GSM-AUTH:" + resp)
  97. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  98. if ev is None:
  99. raise Exception("Connection timed out")
  100. def test_ap_hs20_select(dev, apdev):
  101. """Hotspot 2.0 network selection"""
  102. bssid = apdev[0]['bssid']
  103. params = hs20_ap_params()
  104. params['hessid'] = bssid
  105. hostapd.add_ap(apdev[0]['ifname'], params)
  106. dev[0].hs20_enable()
  107. id = dev[0].add_cred_values(realm="example.com", username="test",
  108. password="secret", domain="example.com")
  109. interworking_select(dev[0], bssid, "home")
  110. dev[0].remove_cred(id)
  111. id = dev[0].add_cred_values(realm="example.com", username="test",
  112. password="secret",
  113. domain="no.match.example.com")
  114. interworking_select(dev[0], bssid, "roaming")
  115. dev[0].set_cred_quoted(id, "realm", "no.match.example.com");
  116. interworking_select(dev[0], bssid, no_match=True)
  117. def test_ap_hs20_ext_sim(dev, apdev):
  118. """Hotspot 2.0 with external SIM processing"""
  119. if not hlr_auc_gw_available():
  120. return "skip"
  121. bssid = apdev[0]['bssid']
  122. params = hs20_ap_params()
  123. params['hessid'] = bssid
  124. params['anqp_3gpp_cell_net'] = "232,01"
  125. params['domain_name'] = "wlan.mnc001.mcc232.3gppnetwork.org"
  126. hostapd.add_ap(apdev[0]['ifname'], params)
  127. dev[0].hs20_enable()
  128. dev[0].request("SET external_sim 1")
  129. dev[0].add_cred_values(imsi="23201-0000000000", eap="SIM")
  130. interworking_select(dev[0], "home")
  131. interworking_ext_sim_connect(dev[0], bssid, "SIM")
  132. check_sp_type(dev[0], "home")